0    课程地址

https://coding.imooc.com/lesson/207.html#mid=15082

 

1    重点关注

1.1    2-3树和红黑树的等价性归纳

2-3树的2节点为黑

2-3树的3节点左侧为红,2-3树的3节点右侧为黑

 

 

 

1.2    2-3树和红黑树的等价性分析

 

 

 

2    课程内容

 

 

3    Coding

3.1    红黑树coding

关键代码:

    /**
     * 获取节点颜色
     * @author weidoudou
     * @date 2023/4/21 20:35
     * @param node 请添加参数描述
     * @return boolean
     **/
    private boolean getColor(Node node){
        if(node == null){
            return BLACK;
        }
        return node.color;
    }

 private static final boolean RED = true;
    private static final boolean BLACK = false;

    //1     定义Node
    class Node{
        private K key;
        private V value;
        private Node left,right;
        private int height;
        private boolean color;

        public Node(K key, V value){
            this.key = key;
            this.value = value;
            this.left = null;
            this.right = null;
            this.height = 1;
            this.color = RED;
        }

        @Override
        public String toString() {
            final StringBuffer sb = new StringBuffer("Node{");
            sb.append("key=").append(key);
            sb.append(", value=").append(value);
            sb.append('}');
            return sb.toString();
        }
    }

 

posted on 2023-04-21 20:22  菜鸟乙  阅读(16)  评论(0编辑  收藏  举报