BinaryTree
of the text is given below.
The new member
template <class T> class BinaryTreeNode { friend BinaryTree<T>; private: T data; BinaryTreeNode<T> *LeftChild, // left subtree *RightChild; // right subtree }; template<class T> class BinaryTree { public: BinaryTree() {root = 0;}; ~BinaryTree(){}; BinaryTree<T>& SwapChildren(); private: BinaryTreeNode<T> *root; // pointer to root };
SwapChildren swaps the
left and right children of every node in a binary tree.
It returns *this.
SwapChildren
member function. You may define and implement new private
member functions as needed.
You may not create or delete any nodes or invoke any binary tree functions
not defined in this problem unless you provide code for these functions.
MinHeap
is given below.
template<class T> class MinHeap { public: MinHeap(int MinHeapSize = 10); ~MinHeap() {delete [] heap;} MinHeap<T>& Insert(const T& x); MinHeap<T>& DeleteMin(T& x); private: T *heap; // 1D array int CurrentSize, // number currently in heap MaxSize; // capacity of heap[] }; template<class T> MinHeap<T>::MinHeap(int MinHeapSize) {// Min heap constructor. MaxSize = MinHeapSize; heap = new T[MaxSize+1]; CurrentSize = 0; }
Insert
member function.
Find(e), where e is an element
at level 7 and we are using path compaction.
ABCDEFGHIJ, and when they are output in postorder,
the output is
BDCAEHGJIF.
Draw the binary tree showing the data in each node and the pointers between
nodes.
feedback form |
permissions |
international |
locate your campus rep |
request a review copy
Copyright ©2001 The McGraw-Hill Companies.
digital solutions |
publish with us |
customer service |
mhhe home
Any use is subject to the
Terms of Use and Privacy Policy.
McGraw-Hill Higher Education is one of the many fine businesses of the
The McGraw-Hill Companies.