If curr left 0 no left subtree curr else

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: t == 0) root = curr->right; currelse if (parent->left == curr) l if parentparent->left = curr->right; currelse parentparent->right = curr->right; curr} } only else if (curr->right == 0) // only left subtree (curr- else { // has both subtrees prev = curr->left; currwhile (prev->right != 0) (prevprev = prev->right; prevprevprev->right = curr->right; currif (parent == 0) root = curr->left; currelse if (parent->left == curr) (parentparentparent->left = curr->left; currelse parentparent->right = curr->left; curr- } And finally, of course, curr would be deleted. curr All we have to do is find the node first. 12 You may find other approaches in books involving replacing the deleted node with its predecessor. This is a simple process if the data is moved, but this move may be computationally expensive. expensive. The method described in this course involves only pointer adjustments. The struct for a node is now struct The need to remember parents, because they are not stored in a node, is similar to the previous node problem with lists. We showed how a doubly-linked list helps here...
View Full Document

This document was uploaded on 04/07/2014.

Ask a homework question - tutors are online