Created
April 1, 2009 02:28
-
-
Save davelyon/88509 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
BinaryNode* BinaryNode::remove(char *n) { | |
int test = strcmp(n,name); | |
BinaryNode *temp; | |
if(test > 0) { //Name we're deleting is bigger | |
if(right != NULL){ | |
right = right->remove(n); | |
return this; | |
} | |
} | |
if(test < 0){ //Name we're deleting is smaller | |
if(left != NULL){ | |
left = left->remove(n); | |
return this; | |
} | |
} | |
if(test == 0) { | |
temp = NULL; | |
if(left != NULL && right != NULL){ | |
temp = right->goLeft(); | |
if(right != temp) | |
temp->right = this->right; | |
else | |
temp->right = NULL; | |
temp->left = this->left; | |
}else{ | |
if(left != NULL){ | |
temp = left; | |
} | |
if(right != NULL){ | |
temp = right; | |
} | |
} | |
left = NULL; | |
right = NULL; | |
delete(this); | |
cout << n << " was deleted." << endl; | |
return temp; | |
} | |
if( (left == NULL && right == NULL) | |
|| (left == NULL && test < 0) | |
|| (right == NULL && test > 0) ) | |
cout << n << " is not in the gradebook and cannot be removed." << endl; | |
return this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment