我们被要求在 Java 中实现一棵红黑树,但我不确定这是如何完成的。如果有人能评论我的节点类以实现 r/b 树,那就太好了。开始了:
public class RBTnode {
public RBTnode(int key, RBTnode left, RBTnode right) {
/* this is the constructor for a root node */
color = 0;
parent = null;
key = this.key;
left = this.left;
right = this.right;
}
public RBTnode(int key, RBTnode left, RBTnode right, RBTnode parent, int color ) {
key = this.key;
color = this.color;
left = this.left;
right = this.right;
parent = this.parent;
}
int color; // 0 black, 1 red
int key;
RBTnode parent;
RBTnode left;
RBTnode right;
}