


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: DATA STRUCTURES; Subject: Computer Science; University: Rensselaer Polytechnic Institute; Term: Fall 2008;
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Write the destroy tree member function. This should effectively be a post-order traversal, with a node being destroyed after its left and right subtrees are destroyed.
First we need to find the node to remove. Once it is found, the actual removal is easy if the node has no children or only one child. It is harder if there are two children:
Exercise: Write a recursive version of erase.
Exercise: Write a simple recursive algorithm to calculate the height of a tree.
Exercise: Implement an algorithm for finding the in-order successor of a node.
// ITERATORS iterator begin() const { if (!root_) return iterator(NULL); TreeNode
private: // REPRESENTATION TreeNode
// PRIVATE HELPER FUNCTIONS TreeNode
iterator find(const T& key_value, TreeNode
std::pair<iterator,bool> insert(const T& key_value, TreeNode
int erase(T const& key_value, TreeNode
void print_in_order(std::ostream& ostr, const TreeNode