/******************************************************************** * PROJECT #3 * KYU BAE 12.12.2000 * < Tree_main.cpp > * ******************************************************************** * * Objective: * The program provide the opportunity to demonstrate the following * 1) A general ability to write and debug a modest size c++ program. * 2) An understanding of classes and templates * 3) An understanding of pointers and * 4) andThe implementation of a singly Linked list * 5) Building a binary tree * 6) Listing binary tree entries in sorted order; * 7) searching a binarytree and combining a singly list with * 8) a binary tree * 9) searching and sorting an array ********************************************************************* * * ********************************************************************/ // #include "Memb.h" #include "tree.h" #include "string2.h" #include "slist.h" #include "Cdinventory.h" // #include #include #include #include #include #include //Global constants const int MaxMember =25; const int STRG_SZ = 4; const int ArraySize=25; void pause (void); //void bubble(char * strings[], int count); /* bubble sort function */ /* prototype for function to hold screen */ /******************************************************************** * main () * dos command line: at dos command line file names are entered * two data file names must be entered * returns interger * ********************************************************************/ int main(int argc, char *argv[]) //Proj3.dat cdinfo.dat { int choice; cout <<"\n\n\n\n\n\n\n\n Menu: \n"; cout <<"******************************************\n"; cout <<"1) Bubble Sort/Binary Search for Surname\n"; cout <<"2) Binary Tree/Quick Search for Title\n"; cout <<"\n0) Quit\n"; cout <<"\nSelect => "; cin>>choice; /**************************************************************************** * choice = 1 * Builds array of last names and sort them by bubble sort and searches * the last name using the binary search. * Proj3.dat at commandline ****************************************************************************/ while (choice!=0) { if (choice ==1) { int result=0; register int i; char answer ='Y'; char searchkey[11]; MemberList TheList; MemberList TwoList; TheList.FileInput(argv[1]); //proj3.dat cout << "\n\n\n***************BUBBLE SORT***************\n"; // for ( i=0;i<25;i++) //{ TwoList.ListTwoPtr=TheList.ListPtr; /* save the starting address of each string */ /* array of strings to sort */ // } TwoList.bubble(TwoList, 24); /* call bubble sort */ TwoList.PrintAllRecord(TwoList); /*pointer array to show sorted strings*/ while(answer=='Y' || answer=='y') { cout <<"\n\n **********************************\n"; cout <<"(You Must Type Only First Letter of Last Name In Upper Case) "; cout <<"\nEnter Last Name You Want To Search: "; cin.getline(searchkey, 11,'\n'); result = TwoList.binarysearch(TwoList, searchkey, 0, ArraySize-1, ArraySize); if (result !=-1) { cout <<" **********************************\n"; cout <<"\n\n <<< Match found >>> \n"; cout << TwoList.ListTwoPtr[result] << endl; cout <<" **********************************\n"; } else { cout <<"\n\n **********************************\n"; cout <<"\n\n " << searchkey <<" <<< Match not found! >>>\n"; cout <<"\n\n **********************************\n"; } cout <<"\n\n Do you want to do another search? (Y/N) "; cin.get(answer); cin.ignore(); } } /**************************************************************************** * choice =2 * builds tree with tokenzied titles then search for the title with just * a word. and print them. * CDinfo.dat * ****************************************************************************/ else { String key; char* tokenPtr; char temp[41]; Cdlist _TheList; Tree< String > stringTree; _TheList._FileInput(argv[2]); //cdinfo.dat for (int i=0; i<37; i++) { strcpy(temp, _TheList._ListPtr[i].title); tokenPtr = strtok(_TheList._ListPtr[i].title, " " ); while ( tokenPtr != 0 ) { String *newString = new String( tokenPtr ); String *newString2 = new String(temp); stringTree.insertNode( *newString, *newString2); tokenPtr = strtok( 0, " " ); } } cout <<"\nList of Words In Order:\n"; cout <<"*************************\n\n"; stringTree.inOrderTraversal(); cout <<"\n\nEnter a word to search for the title: "; cin>>key; stringTree.searchTree( key); } cout <<"\n\n\n Menu: \n"; cout <<"******************************************\n"; cout <<"1) Bubble Sort/Binary Search for Surname\n"; cout <<"2) Binary Tree/Quick Search for Title\n"; cout <<"\n0) Quit\n"; cout <<"\nSelect => "; cin>>choice; } return 0; } /* function to hold the display until a key is pressed */ /******************************************************************** * * * ********************************************************************/