18.BinaryTrees-13 - Deletion from a Binary Tree Last time...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Deletion from a Binary Tree Last time we outlined how to delete a node from a binary tree. We broke up our work into three cases: 1) Deleting a leaf node 2) Deleting a node with one child 3) Deleting a node with two children. Keep these three in mind, as well as how we determined the delete would work in these cases when looking at this code. For a leaf node, our job isn't too hard. The key will be identifying the parent of the node to delete. (Actually, we'll do this in the other cases as well.) Once we do this, then we just have to set the appropriate node to NULL: parert->left = NULL or parent->right = NULL For the second task, we'll need to find the parent node of the node to be deleted, along with the sole child node of the node to be deleted and "connect them." Here are the four possibilities: 10 10 / \ / \ 5 15 ====> 1 15 (delete 5) / 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 10 / \ / \ 5 15 ====> 7 15 (delete 5) \ 7 10 10 / \ / \ 5 15 ====> 7 12 (delete 15) / 12 10 10 / \ / \ 5 15 ====> 7 23 (delete 15) \ 23 In each of these two main cases, I am still glossing over a
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

18.BinaryTrees-13 - Deletion from a Binary Tree Last time...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online