1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
int main()
{
// string filename=ReadLine("Please enter the name of the file : ");
ifstream fin;
// fin.open(filename.c_str());
fin.open("data.txt");
struct timeval start, end, diff;
if (fin.fail())
{
cout<<"Unable to open the specified file name "<<endl;
return 0;
}
else
{
string selectengine=ReadLine("Please Enter the representation to use: 1.List, 2.BST, 3.AVL \n >");
int select=atoi(selectengine.c_str());
switch (select)
{
case 1:
{
ListEngine* Google=new ListEngine();
break;
}
case 2:
{
BST* Google=new BST();
break;
}
case 3:
{
// AVL* Google=new AVL();
break;
}
default:
{
cout<< "Invalid option, choosing List as SearchEngine ."<<endl;
ListEngine* Google=new ListEngine();
break;
}
}
// BST* Google=new BST();
gettimeofday(&start, NULL);
Google->LoadData(fin);
gettimeofday(&end, NULL);
timeval_subtract(&diff, &end, &start);
cout << "File Loaded Successfully in " << diff.tv_sec << " seconds and " << diff.tv_usec << " microseconds." << endl;
fin.close();
int choice=0;
while (choice!=2)
{
string c=ReadLine(" Please choose : 1.Search 2.Exit 3.Delete a word \n >");
choice=atoi(c.c_str());
switch (choice)
{
case 1:
{
string word=ReadLine("Please enter a word to search : \n > ");
gettimeofday(&start, NULL);
Google->SearchResults(word);
gettimeofday(&end, NULL);
timeval_subtract(&diff, &end, &start);
cout << "Search took " << diff.tv_sec << " seconds and " << diff.tv_usec << " microseconds." << endl;
break;
}
case 2:
{
break;
}
case 3:
{
string word=ReadLine("Please enter the word to delete: \n > ");
// Google->DeleteWord(word);
break;
}
default:
{
cout<< "Invalid Choice "<<endl;
}
}
}
// delete Google;
}
}
|