Using the template class NTree studied in tutorial 11 and the template class Queue defined in this problem set, add tree traversal to class NTree: #pragma once #include #include “TreeVisitor.h” template class NTree { private: T fKey; // T() for empty NTree NTree<t,n>* fNodes[N]; // N subtrees of degree N NTree(); // sentinel constructor public: static NTree<t,n> NIL; // sentinel NTree( const T& aKey ); // a simple NTree with key and N subtrees virtual ~NTree(); // destructor NTree( const NTree& aOtherNTree ); // copy constructor NTree& operator=( const NTree& aOtherNTree ); // assignment operator virtual NTree* clone(); // clone a tree bool isEmpty() const; // is tree empty const T& key() const; // get key (node value) // indexer (allow for result modification by client – no const in result) NTree& operator[]( unsigned int aIndex ) const; // tree manipulators (using constant references) void attachNTree( unsigned int aIndex, const NTree<t,n>& aNTree ); const NTree& detachNTree( unsigned int aIndex ); // depth-first traversal void traverseDepthFirst( const TreeVisitor& aVisitor ) const; // breadth-first traversal void traverseBreadthFirst( const TreeVisitor& aVisitor ) const; }; Use “TreeVisitor.h” available on Canvas as a start to implement the tree traversal.</t,n></t,n></t,n>

Using the template class List with proper copy control, implement the template class Queue as specified below: #pragma once #include “List.h” #include template class Queue { private: List fElements; public: bool isEmpty() const; int size() const; void enqueue( const T& aElement ); void dequeue(); const T& top() const; // stack indexer const T& operator[]( size_t aIndex ) const; // stack iterators Iterator begin() const; Iterator end() const; Iterator rbegin() const; Iterator rend() const; }; That is, Queue is a queue container type that can grow in size on demand. Complete the implementation of the template class Queue.

Test harness: Queue lQueue; lQueue.enqueue( 1 ); lQueue.enqueue( 2 ); lQueue.enqueue( 3 ); lQueue.enqueue( 4 ); lQueue.enqueue( 5 ); lQueue.enqueue( 6 ); // iterate from the top cout << “A – Top to bottom: ” << lQueue.size() << ” elements” << endl; for ( const int& item : lQueue ) { cout << “A queue element: ” << item << endl; } // iterate from the bottom cout << “B – Bottom to top: ” << lQueue.size() << ” elements” << endl; for ( Queue::Iterator iter = lQueue.rbegin(); iter != iter.rend(); iter– ) { cout << “A queue element: ” << *iter << endl; } cout << “Queue elements:” << endl; for ( ; !lQueue.isEmpty(); lQueue.dequeue() ) { cout << “value: ” << lQueue.top() << endl; } Result: A – Top to bottom: 6 elements A queue element: 1 A queue element: 2 A queue element: 3 A queue element: 4 A queue element: 5 A queue element: 6 B – Bottom to top: 6 elements A queue element: 6 A queue element: 5 A queue element: 4 A queue element: 3 A queue element: 2 A queue element: 1 Queue elements: value: 1 value: 2 value: 3 value: 4 value: 5 value: 6

Place New Order
It's Free, Fast & Safe

"Looking for a Similar Assignment? Order now and Get a Discount!