Advertisement
satyaki30

deleting leaves the weird way

Oct 25th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. void delete_leaf(BSTNode *tnode)
  2. {
  3.     //deletes the leaf node tnode from the BST - works
  4.     BSTNode *ptr, *pre_ptr;
  5.  
  6.     ptr = root;
  7.     pre_ptr = root; //pre_ptr is the parent of the root
  8.  
  9.  
  10.     while (ptr -> data != tnode -> data)
  11.     {
  12.         pre_ptr = ptr;
  13.         printf("\ntnode -> data = %d, ptr -> data =%d\n", tnode -> data, ptr -> data);
  14.         if (ptr -> data < tnode -> data)
  15.         {
  16.             printf("\ntaking left");
  17.             ptr = ptr -> left;
  18.         }
  19.        
  20.         else
  21.         {
  22.             printf("\ntaking right");
  23.             ptr = ptr -> right;
  24.         }
  25.     }
  26.  
  27.     free(ptr);
  28.  
  29.     pre_ptr -> right = NULL;
  30.     pre_ptr -> left = NULL;
  31.  
  32.     //print_ascii_tree(root);
  33.    
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement