Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct tree_node* successor(struct tree_node *root) {
- if (root == NULL)
- return;
- if (root->right_child != NULL)
- {
- struct tree_node *iterator = root->right_child;
- while (iterator->left_child != NULL)
- {
- iterator = iterator->left_child;
- return iterator;
- }
- }
- else
- {
- struct tree_node *iterator = root;
- while (root->parent->right_child == root)
- {
- iterator = root->parent;
- }
- if (root->parent != NULL)
- {
- return root->parent;
- }
- else
- {
- printf("No successor!");
- return NULL;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement