Outline Of A Red Black Tree

736 Words3 Pages
/**Implement Red Black Tree * RedBlackTreeNode Class **/ class RBTNode { RBTNode lChild, rChild; int el; int colour; public RBTNode(int element) { this( element, null, null ); } public RBTNode(int element, RBTNode l, RBTNode r) { lChild = l; rChild = r; el = element; colour = 1; } } /** Class RBTree **/ class RBTree { private RBTNode actual; private RBTNode parent; private RBTNode grandNode; private RBTNode greatNode; private RBTNode root; private static RBTNode nullN; static { nullN = new RBTNode(0); nullN.lChild = nullN; nullN.rChild = nullN; } /** Black = 1 , Red = 0 **/ static final int black = 1; static final int red = 0; public RBTree(int neg) { root = new RBTNode(neg); root.lChild = nullN; root.rChild = nullN; } /** Checking tree emptiness **/ public boolean isTreeEmpty() { return root.rChild == nullN; } /** Making tree empty **/ public void makeTreeEmpty() { root.rChild = nullN; } /** Inserting item **/ public void insertItem(int elem) { actual = parent = grandNode = root; nullN.el = elem; while (actual.el != elem) { greatNode = grandNode; grandNode = parent;
Open Document