Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
#include
#include
#include
#include
#include
<stdio.h>
<stdlib.h>
<string.h>
<ctype.h>
<conio.h>
<iostream>
}
// display all the words stored through trie children
for (count = 26; count >= 0; count--)
DisplayTrie(trie->pChildren[count], nivel + 4);
}
}
void Complete(TrieNode *trie,char str[20])
{
int count;
if(trie)
{
if (trie->NotLeaf != true && strncmp( str ,trie -> word,strlen(s
tr) )== 0 ) // if TrieNode is a leaf(a word is stored in)
{
cout << trie->word << endl;
}
// display all the words stored through trie children with this
property
for (count = 26; count >= 0; count--)
Complete(trie->pChildren[count], str);
}
}
int main()
{
TrieNode *trie;
char UserInputWord[20], cont_insert=' ';
int option = 0; //stores the user's input(the chosen option)
char str[20] ;
trie = NULL;
label_menu:
while( option != 5)
{
//display menu
cout << endl << "
Menu: " << endl;
cout <<
"___________________________________________" <<
endl;
cout << "
1. Create tree\n
2. Insert node\n
3. Search fo
r node\n
4. Complete\n
5. Display\n
6. Exit\n";
//get user input
cout << "\n\n\nInput choice: ";
cin >> option;
switch (option)
{
case 1:
//Create tree
while(cont_insert != 'n')
{
// get user input string
break;
//Insert node
cout << endl << "Insert word :\n";
cin >> UserInputWord;
Insert(trie,UserInputWord);
case 3:
break;
//Search for node
cout << endl << "Searched word :";
cin >> UserInputWord;
Find(trie,UserInputWord);
case 4:
break;
//Display tree
//Complete(trie,"g");
cout << endl << "Insert word :";
cin >> str;
Complete(trie,str);
break;
case 5:
case 6:
DisplayTrie(trie ,0);
//Exit
break;
default:
cout << "Choose from the displayed options (1-5) !!!"
;
goto label_menu;
}//end switch
}//end while
system("PAUSE");
return 0;
}