Created
April 1, 2009 02:24
-
-
Save paulerickson/88508 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool node::del(node*& p, string n) { | |
83 if (n < name) //to the left | |
84 if (l) | |
85 return l->del(l, n); | |
86 else | |
87 return 0; | |
88 | |
89 if (n > name) //to the right | |
90 if (r) | |
91 return r->del(r, n); | |
92 else | |
93 return 0; | |
94 | |
95 // //same name | |
96 if (l && r) { | |
97 name = r->farleftval(); //take successor value | |
98 return r->del(r, name); //delete successor, ignoring return | |
99 } | |
100 if (l) //only left child | |
101 p = l; //point parent to lchild | |
102 if (r) //only right child | |
103 p = r; //point parent to rchild | |
104 if (!l && !r) | |
105 p = NULL; //no children | |
106 | |
107 delete this; | |
108 return 1; | |
109 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment