Sunday, 15 June 2014

How to create the sentinel NIL object in a red black tree in C++? -


I want to apply a red black tree but I am battling basic steps. I am used to using structs only, but now I want to clean it and use classes.

I want to make a special object, zero (tree member?) (Zero color is black and all the nodes refer to this single object, CLRS says, "T. NIL One object is the same quality as the normal node, its color is black and its left, right and P properties can be considered arbitrary "," We all use a guardian T.nil to represent NIL ") < / P>

How do I get left, right, P to zero What? For the first time, should a separate singleton class be made and then used in the definition of the tree? When i t Allot NLs (comments) I am getting errors now

  #include & lt; Iostream & gt; Enum color_t {red, black}; Class tree; // Announce Tree * T; Class node {// can be a straight one! Public: int data; Color_t color = red; Node * left; Node * true; Node * guardian; Node () {// default constructor left = t-> Zero; // Error: Member irrevocable type entered in true = T-> Zero; // Error: member incomplete kind of parent = t- & gt; Zero; // error: member access in incomplete type) node (int d, color_t c) {// if data and color nodes are (known); Data = D; Color = C; }}; Square tree {public: node * route; Node * zero; Tree (); Insert zero (int d); Invalid left rotate (node ​​* x); }; Tree :: tree () {NIL = new node (); Zero-> Color = black; Root = zero; }  

to transfer the body of the node :: node () Required forward in your code; Anything defined after square tree (at the point you have, tree is declared only).


No comments:

Post a Comment