{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

10b - TreesSlides

5 two other ways of accessing the nodes preorder and

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

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

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern