1. | 1. Please complete the following implementation: template < class Item > |
2. | binary_tree_node <Item>* tree_copy (const binary_tree_node <Item>* root_ptr) |
Using the previous implementation, complete the following function for the bag class given in Appendix 1: | |
1. | template < class Item > |
2. | void bag <Item>::operator = (const bag<Item>& source) |
3. | // Header file used: bintree.h |
- For the bag class defined in Appendix 1, please complete the following function:
- template < class Item >
- void bag<Item>::insert(const Item& entry)
- // Postcondition: A new copy of entry has been inserted into the bag.
- // Header file used: bintree.h
- Write a function to perform left-right rotation on the following AVL tree. The figure shows the steps. (Note: Please implement the function in two steps: (1) left rotation, (2) right rotation.)
parent
- template < class Item >
- binary_tree_node <Item>* left_right_rotation (binary_tree_node <Item>*& parent) {
- binary_tree_node <Item>* temp;
- Add the following numbers to an AVL tree. Please draw the final tree. 2, 4, 6, 8, 10, 12, 20, 18, 16, 14
- The following functions are available:
Also assume the following functions are available:
- binary_tree_node<Item>* left_rotation (binary_tree_node<Item>*& parent)
- binary_tree_node<Item>* right_rotation (binary_tree_node<Item>*& parent)
- binary_tree_node<Item>* left_right_rotation (binary_tree_node<Item>*& parent)
- binary_tree_node<Item>* right_left_rotation (binary_tree_node<Item>*& parent)
Complete the following function, which balances a tree rooted at temp.
- template < class Item >
- binary_tree_node<Item>* balance(binary_tree_node <Item>*& temp)
- Please implement the following function (recursively).
- template < class Item >
- void flip(binary_tree_node < Item > * root_ptr)
- // Precondition: root_ptr is the root pointer of a non-empty binary tree. // Postcondition: The tree is now the mirror image of its original value.
Example:
// 1 1
// / /
// 2 3 3 2
// / /
// 4 5 5 4
- template < class Item >
- void flip (binary_tree_node <Item>* root_ptr)
Appendix 1: Bag class with binary search tree.
Reviews
There are no reviews yet.