Advertisement
Aodai

Untitled

Apr 16th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. struct tree_node* successor(struct tree_node *root) {
  2.     if (root == NULL)
  3.         return;
  4.  
  5.    
  6.     if (root->right_child != NULL)
  7.     {
  8.         struct tree_node *iterator = root->right_child;
  9.         while (iterator->left_child != NULL)
  10.         {
  11.             iterator = iterator->left_child;
  12.             return iterator;
  13.         }
  14.     }
  15.     else
  16.     {
  17.         struct tree_node *iterator = root;
  18.         while (root->parent->right_child == root)
  19.         {
  20.             iterator = root->parent;
  21.         }
  22.         if (root->parent != NULL)
  23.         {
  24.             return root->parent;
  25.         }
  26.         else
  27.         {
  28.             printf("No successor!");
  29.             return NULL;
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement