5 two other ways of accessing the nodes preorder and

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: efix indicates when the node is visited. z For our example: For our example: 8 9 7 x inorder: y prepre-order: z, x, y, w, t, r, v, s postpost-order: t, r, w, s, v, y, x, z w v r t s 5 2 6 2 5 6 0 2 0 8 7 6 9 8 7 inorder: 0, 2, 5, 6, 7, 8, 9 inorder: 0, 2, 5, 6, 7, 8, 9 preorder: 9 preorder: 5, 2, 0, 6, 8, 7, 9 postorder: 8 5 2 Tree destruction: destruction The last traversal order visits the node last. If we delete nodes as we visit them, we can delete an entire tree. 6 0 8 7 9 void PostOrderDelete(nodePtr curr) inorder: 0, 2, 5, 6, 7, 8, 9 { if (curr != 0) preorder: 5, 2, 0, 6, 8, 7, 9 { PostOrderDelete(currPostOrderDelete(curr->left); postorder: 0, 2, 7, 9, 8, 6, 5 PostOrderDelete(currPostOrderDelete(curr->right); delete curr; So the destruction function is void destroy_tree(nodePtr root) { PostOrderDelete(root); } What if we want to delete a data value from the structure. We have to find the node containing the value, and remove it. But we can't destroy the structure. If the node bein...
View Full Document

Ask a homework question - tutors are online