Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void delete_leaf(BSTNode *tnode)
- {
- //deletes the leaf node tnode from the BST - works
- BSTNode *ptr, *pre_ptr;
- ptr = root;
- pre_ptr = root; //pre_ptr is the parent of the root
- while (ptr -> data != tnode -> data)
- {
- pre_ptr = ptr;
- printf("\ntnode -> data = %d, ptr -> data =%d\n", tnode -> data, ptr -> data);
- if (ptr -> data < tnode -> data)
- {
- printf("\ntaking left");
- ptr = ptr -> left;
- }
- else
- {
- printf("\ntaking right");
- ptr = ptr -> right;
- }
- }
- free(ptr);
- pre_ptr -> right = NULL;
- pre_ptr -> left = NULL;
- //print_ascii_tree(root);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement