PrintTree (root)i Generate the Driver file (main.cpp) where you perform the following tasks: Operation to Be Tested and Description of Action oput Values ||Expected Output Create a tree object • Print if the tree is empty or not • Insert ten items |Tree is empty 9 273 11 17 0 5 1 || Print if the tree is empty or not ITree is not empty Print the length of the tree Retrieve 9 and print whether found or not tem is found

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Using the header file and the .cpp file provided, generate the driver file(main.cpp) and print out the following outputs

template <class ItemType>
void Insert (TreeNode<ItemType>*& tree,
template <class ItemType>
void PreOrder (TreeNode<ItemType>* tree,
QueType<ItemType>& Que)
template <class ItemType>
void PrintTree (TreeNode<ItemType>* tree)
ItemType item)
if (tree != NULL)
if (tree == NULL)
if (tree != NULL)
PrintTree (tree->left);
Que. Enqueue (tree->info) :
PreOrder (tree->left, Que);
tree = new TreeNode<ItemType>;
cout << tree->info << " ";
PrintTree (tree->right);
tree->right = NULL;
tree->left = NULL;
tree->info = item;
PreOrder (tree->right, Que) ;
template <class ItemType>
void TreeType<ItemType>: :Print ()
else if (item < tree->info)
template <class ItemType>
Insert (tree->left, item);
void InOrder (TreeNode<ItemType>* tree,
else
QueType<ItemType>s Que)
PrintTree (root);
Insert (tree->right, item);
if (tree != NULL)
template <class ItemType>
void TreeType<ItemType>::InsertItem (ItemType
InOrder (tree->left, Que);
Que. Enqueue (tree->info) ;
InOrder (tree->right, Que);
item)
Generate the Driver file (main.cpp) where you perform the following tasks:
Insert (root, item);
Input Values
Expected Output
Operation to Be Tested and Description of Action
Create a tree object
template <class ItemType>
void Delete (TreeNode<ItemType>*s tree,
template <class ItemType>
void PostOrder (TreeNode<ItemType> tree,
ITree is empty
Print if the tree is empty or not
ItemType item)
QueType<ItemType>s Que)
Insert ten items
4 9 273 11 17 0 5 1||
if (item < tree->info)
Delete (tree->left, item);
else if (item > tree->info)
if (tree ! = NULL)
Print if the tree is empty or not
ITree is not empty
|10
Item is found
PostOrder (tree->left, Que) ;
Print the length of the tree
Delete (tree->right, item) ;
PostOrder (tree->right, Que);
else
Que. Enqueue (tree->info);
Retrieve 9 and print whether found or not
DeleteNode (tree);
Item is not found
o 1 2 3 4 5 7 9 11 17
14 2 013975 11 17
Retrieve 13 and print whether found or not
template <class ItemType>
template <class ItemType>
Print the elements in the tree (inorder)
void DeleteNode (TreeNode<ItemType>*& tree)
void TreeType<ItemType>: :ResetTree (OrderType
order)
Print the elements in the tree (preorder)
ItemType data;
Print the elements in the tree (postorder)
|1 03 25 7 17 11 9 4
TreeNode<ItemType> tempPtr;
switch (order)
Make the tree empty
case PRE_ORDER:
PreOrder (root, preQue);
tempPtr = tree;
if (tree->left == NULL)
break;
case IN ORDER:
InOrder (root, inQue);
tree = tree->right;
delete tempPtr;
break;
case POST_ORDER:
PostOrder (root, postQue);
break;
else if (tree->right == NULL)
tree = tree->left;
delete tempPtr;
template <class ItemType>
void TreeType<ItemType>::GetNextItem (ItemTypes
else
GetPredecessor (tree->left, data);
tree->info = data;
Delete (tree->left, data);
item, OrderType order, bool& finished)
finished = false;
switch (order)
template <class ItemType>
void GetPredecessor (TreeNode<ItemType>*
tree, ItemTypes data)
case PRE_ORDER:
preQue. Dequeue (item);
if (preQue. IsEmpty ())
finished = true;
while (tree->right != NULL)
tree = tree->right;
break;
case IN ORDER:
inQue. Dequeue (item);
if(inQue.IsEmpty ())
data = tree
nfo;
template <class ItemType>
void TreeType<ItemType>::DeleteItem (ItemType
item)
finished = true;
break;
case POST ORDER:
postQue. Dequeue (item);
Delete (root, item);
if (postQue.IsEmpty ())
finished = true;
break;
Transcribed Image Text:template <class ItemType> void Insert (TreeNode<ItemType>*& tree, template <class ItemType> void PreOrder (TreeNode<ItemType>* tree, QueType<ItemType>& Que) template <class ItemType> void PrintTree (TreeNode<ItemType>* tree) ItemType item) if (tree != NULL) if (tree == NULL) if (tree != NULL) PrintTree (tree->left); Que. Enqueue (tree->info) : PreOrder (tree->left, Que); tree = new TreeNode<ItemType>; cout << tree->info << " "; PrintTree (tree->right); tree->right = NULL; tree->left = NULL; tree->info = item; PreOrder (tree->right, Que) ; template <class ItemType> void TreeType<ItemType>: :Print () else if (item < tree->info) template <class ItemType> Insert (tree->left, item); void InOrder (TreeNode<ItemType>* tree, else QueType<ItemType>s Que) PrintTree (root); Insert (tree->right, item); if (tree != NULL) template <class ItemType> void TreeType<ItemType>::InsertItem (ItemType InOrder (tree->left, Que); Que. Enqueue (tree->info) ; InOrder (tree->right, Que); item) Generate the Driver file (main.cpp) where you perform the following tasks: Insert (root, item); Input Values Expected Output Operation to Be Tested and Description of Action Create a tree object template <class ItemType> void Delete (TreeNode<ItemType>*s tree, template <class ItemType> void PostOrder (TreeNode<ItemType> tree, ITree is empty Print if the tree is empty or not ItemType item) QueType<ItemType>s Que) Insert ten items 4 9 273 11 17 0 5 1|| if (item < tree->info) Delete (tree->left, item); else if (item > tree->info) if (tree ! = NULL) Print if the tree is empty or not ITree is not empty |10 Item is found PostOrder (tree->left, Que) ; Print the length of the tree Delete (tree->right, item) ; PostOrder (tree->right, Que); else Que. Enqueue (tree->info); Retrieve 9 and print whether found or not DeleteNode (tree); Item is not found o 1 2 3 4 5 7 9 11 17 14 2 013975 11 17 Retrieve 13 and print whether found or not template <class ItemType> template <class ItemType> Print the elements in the tree (inorder) void DeleteNode (TreeNode<ItemType>*& tree) void TreeType<ItemType>: :ResetTree (OrderType order) Print the elements in the tree (preorder) ItemType data; Print the elements in the tree (postorder) |1 03 25 7 17 11 9 4 TreeNode<ItemType> tempPtr; switch (order) Make the tree empty case PRE_ORDER: PreOrder (root, preQue); tempPtr = tree; if (tree->left == NULL) break; case IN ORDER: InOrder (root, inQue); tree = tree->right; delete tempPtr; break; case POST_ORDER: PostOrder (root, postQue); break; else if (tree->right == NULL) tree = tree->left; delete tempPtr; template <class ItemType> void TreeType<ItemType>::GetNextItem (ItemTypes else GetPredecessor (tree->left, data); tree->info = data; Delete (tree->left, data); item, OrderType order, bool& finished) finished = false; switch (order) template <class ItemType> void GetPredecessor (TreeNode<ItemType>* tree, ItemTypes data) case PRE_ORDER: preQue. Dequeue (item); if (preQue. IsEmpty ()) finished = true; while (tree->right != NULL) tree = tree->right; break; case IN ORDER: inQue. Dequeue (item); if(inQue.IsEmpty ()) data = tree nfo; template <class ItemType> void TreeType<ItemType>::DeleteItem (ItemType item) finished = true; break; case POST ORDER: postQue. Dequeue (item); Delete (root, item); if (postQue.IsEmpty ()) finished = true; break;
binarysearchtree.h
#ifndef BINARYSEARCHTREE_H_INCLUDED
#define BINARYSEARCHTREE_H_INCLUDED
#include "quetype.h"
template <class ItemType>
template <class ItemType>
bool TreeType<ItemType>::IsEmpty ()
return root NULL;
struct TreeNode
template <class ItemType>
bool TreeType<ItemType>::IsFull ()
ItemType info;
TreeNode* left;
TreeNode<ItemType>* location;
TreeNode* right;
try
enum OrderType (PRE_ORDER, IN ORDER,
POST ORDER};
location = new TreeNode<ItemType>;
delete location;
template <class ItemType>
return false;
class TreeType
catch (bad alloc& exception)
public:
TreeType () :
-TreeType ():
void MakeEmpty ();
bool IsEmpty ();
return true;
template <class ItemType>
bool IsFull ();
int CountNodes (TreeNode<ItemType>* tree)
int LengthIs ();
if (tree == NULL)
return 0;
void RetrieveItem (ItemTypes item,
bools found);
void InsertItem (ItemType item) ;
void DeleteItem (ItemType item) ;
void ResetTree (OrderType order):
void GetNextItem (ItemType& item,
else
return CountNodes (tree->left) +
CountNodes (tree->right) + 1;
OrderType order, bool& finished);
template <class ItemType>
void Print ();
int TreeType<ItemType>::LengthIs ()
private:
TreeNode<ItemType>* root;
return CountNodes (root);
QueType<ItemType> preQue;
QueType<ItemType> inQue;
QueType<ItemType> postQue;
template <class ItemType>
void Retrieve (TreeNode<ItemType>* tree, ItemType&
item, bool& found)
#endif // BINARYSEARCHTREE H INCLUDED
binarysearchtree.cpp
#include "binarysearchtree.h"
#include "quetype.cpp"
#include <iostream>
if (tree == NULL)
found = false;
else if (item < tree->info)
Retrieve (tree->left, item, found);
using namespace std;
template <class ItemType>
else if (item > tree->info)
Retrieve (tree->right, item, found);
TreeType<ItemType>::TreeType ()
else
root = NULL;
item = tree->info;
found = true;
template <class ItemType>
void Destroy (TreeNode<ItemType>* tree)
}
template <oclass ItemType>
if (tree !- NULL)
void TreeType<ItemType>::RetrieveItem (ItemTypes
item, bools found)
Destroy (tree->left);
Destroy (tree->right);
Retrieve (root, item, found);
delete tree;
tree = NULL;
template <class ItemType>
TreeType<ItemType>::-TreeType ()
Destroy (root);
template <class ItemType>
void TreeType<ItemType>: :MakeEmpty ()
Destroy (root);
Transcribed Image Text:binarysearchtree.h #ifndef BINARYSEARCHTREE_H_INCLUDED #define BINARYSEARCHTREE_H_INCLUDED #include "quetype.h" template <class ItemType> template <class ItemType> bool TreeType<ItemType>::IsEmpty () return root NULL; struct TreeNode template <class ItemType> bool TreeType<ItemType>::IsFull () ItemType info; TreeNode* left; TreeNode<ItemType>* location; TreeNode* right; try enum OrderType (PRE_ORDER, IN ORDER, POST ORDER}; location = new TreeNode<ItemType>; delete location; template <class ItemType> return false; class TreeType catch (bad alloc& exception) public: TreeType () : -TreeType (): void MakeEmpty (); bool IsEmpty (); return true; template <class ItemType> bool IsFull (); int CountNodes (TreeNode<ItemType>* tree) int LengthIs (); if (tree == NULL) return 0; void RetrieveItem (ItemTypes item, bools found); void InsertItem (ItemType item) ; void DeleteItem (ItemType item) ; void ResetTree (OrderType order): void GetNextItem (ItemType& item, else return CountNodes (tree->left) + CountNodes (tree->right) + 1; OrderType order, bool& finished); template <class ItemType> void Print (); int TreeType<ItemType>::LengthIs () private: TreeNode<ItemType>* root; return CountNodes (root); QueType<ItemType> preQue; QueType<ItemType> inQue; QueType<ItemType> postQue; template <class ItemType> void Retrieve (TreeNode<ItemType>* tree, ItemType& item, bool& found) #endif // BINARYSEARCHTREE H INCLUDED binarysearchtree.cpp #include "binarysearchtree.h" #include "quetype.cpp" #include <iostream> if (tree == NULL) found = false; else if (item < tree->info) Retrieve (tree->left, item, found); using namespace std; template <class ItemType> else if (item > tree->info) Retrieve (tree->right, item, found); TreeType<ItemType>::TreeType () else root = NULL; item = tree->info; found = true; template <class ItemType> void Destroy (TreeNode<ItemType>* tree) } template <oclass ItemType> if (tree !- NULL) void TreeType<ItemType>::RetrieveItem (ItemTypes item, bools found) Destroy (tree->left); Destroy (tree->right); Retrieve (root, item, found); delete tree; tree = NULL; template <class ItemType> TreeType<ItemType>::-TreeType () Destroy (root); template <class ItemType> void TreeType<ItemType>: :MakeEmpty () Destroy (root);
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY