Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
h"
#include <iostream>
#include<iomanip>
#include <string>
using namespace std;
const int maxSize=30;
class treenode // a record holding all the data and pointer for ea
ch item
{
public:
char data[20]; // the data field
char deldata; // indicates if data has been deleted
int left; // the left pointer field
int right; // the right pointer field
};
void main()
{
char option;
int root=-1, free=0; //the start of the list
treenode tree[maxSize];//an array of records holding all the list elements inf
o
initialise(tree, root, free);
do
{
list(tree,root,free);
cout<<endl<<endl<<endl;
cout<<"Menu"<<endl<<endl;
cout<<"1. In-order tree traversal"<<endl;
cout<<"2. Pre-order tree traversal"<<endl;
cout<<"3. Post-order tree traversal"<<endl;
cout<<"4. Find an item"<<endl;
cout<<"5. Insert an item"<<endl;
cout<<"6. Delete an item"<<endl;
cout<<"7. Quit system"<<endl<<endl;
cout<<"Please enter option choice :";
cin>>option;
switch (option)
{
case '1': inorder(tree, root);
break;
case '2': preorder(tree, root);
break;
case '3': postorder(tree, root);
break;
case '4': findnode(tree, root);
break;
case '5': addnode(tree,root,free);
break;
case '6': delnode(tree,root,free);
break;
case '7':cout<<"Quitting system"<<endl;
break;
default: cout<<"you have entered an incorrect option choice plea
se try again"<<endl<<endl;
}
}
while (option!='7');
}