Implement an AVL tree based dictionary. Using your dictionary write a program
that reads a text file specified as a command-line argument and prints out a lexicographically
sorted list of all the words that occur in this file along with the frequency with each
word occurs.
Your dictionary class must be called Dictionary. Your dictionary will be represented
as an AVL tree. Each node in the tree will be an object of class WordNode that
contains: a word, the number of times the word has been accessed, a boolean variable to
support lazy deletion, its height in the tree and links to its left and right children.
The following public methods of Dictionary class must be implemented:
bool isEmpty() const - returns true if empty, false otherwise.
int getSize() - returns how many words are stored in the dictionary.
void insert (String word) - insert word into dictionary if not already present,
else update.
bool find(String word, WordNode & x) - returns true if the word is present and
place data in x.
void printSorted() const - prints the words in the tree in lexicographic order
void remove (String word) - implements the lazy deletion of a node.
In lazy deletion, instead of deleting the desired node and modifying the
structure of the tree, we merely mark the node as deleted. During find operations,
we return false if the desired node is found but marked. This way, the balance of
a tree is never disturbed by deletion operations. However, if too many nodes are
deleted, then operations start to become expensive, since too much of the tree is
devoted to nodes that don’t represent valid data.
This project requires you to learn how to use command line arguments and the
string manipulation package <string>.
int bstree::nonodes(nodeptr p)
{
int count=0;
if (p!=NULL)
{
nonodes(p->left);
nonodes(p->right);
count++;
}
return count;
}
int main()
{
//clrscr();
nodeptr root,root1,min,max;//,flag;
string a,findele,delele;
int choice;
char ch='y';
bstree bst;
//system("clear");
root = NULL;
root1=NULL;
do
{
cout<<"Enter 1 to insert a new node"<<endl;
cout<<"Enter 2 to search a value"<<endl;
cout<<"Enter 3 to delete a value"<<endl;
cout<<"Enter 4 to display printSorted"<<endl;
cout<<"Enter 5 to display the height of the tree"<<endl;
cout<<"Enter 0 to exit"<<endl;
cout<<"\nEnter the choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"\n\t\tADDING NEW NODE"<<endl;
cout<<"\t\t:::::::::::::\n"<<endl;
cout<<"Enter a new value: ";
cin>>a;
bst.insert(a,root);
cout<<"\nThe new value have been added to your tree successfully\n"<<endl;
break;
case 2:
cout<<"\nEnter node to search: ";
cin>>findele;
if (root != NULL)
{
bst.find(findele,root);
}
break;
case 3:
cout<<"\nEnter node to delete: ";
cin>>delele;
bst.del(delele,root);
bst.printSorted(root);
cout<<endl;
break;
case 4:
cout<<"\n\t\tIN-ORDER TRAVERSAL"<<endl;
bst.printSorted(root);
cout<<endl;
break;
case 5:
cout<<"\n\t\tHEIGHT\n"<<endl;
cout<<"The height of the tree is: " <<bst.bsheight(root)<<endl;
break;
case 0:
cout<<"\n\tThank your for using AVL tree program\n"<<endl;
break;
default:
cout<<"Sorry! wrong input\n"<<endl;
break;
}
system("pause");
}while(choice != 0);
return 0;
}
Can you wrap your code in code tags? I recognize that this is your first post on the forum, so here is the guide to using code tags: http://www.cplusplus.com/articles/z13hAqkS/
You seem to have shown us code you wrote(?) But you haven't said what is wrong with it or why you are posting it here. What do you need help with?