// ***************************************************************** // Author: Zhixiang Chen // Class: CSCI/CMPE 1170, Spring 2009 // Lab 23: Binary search // Date: January 23, 2009 // Comment: The code here is meant to be revised. // //----------------------------------------------------------------- // // This lab exercise is to show how to do binary search. // Binary search only works for sorted list. // // Compile and run your program. When everything is fine, // print your .cpp and .h files and turn them to me or the TA // ***************************************************************** #include < iostream > #include #include < string > #include < cstring > #include < cmath> #include #include #include "lab_23_head.h" using namespace std; int main( ) { const int SIZE=20; //list or array size int list[SIZE]={101, 142, 147, 189, 199, 207, 222, 234, 289, 296, 310, 319, 388, 394, 417, 429, 447, 521, 536, 600}; int value; //tagert value int count; //comparisons of performance metric int pos; //position of the target if found or -1 char choice; //flag for yes or no choice //show list showList(list, SIZE); //loop to play search again and again do { //get a target value cout<<"Enter a target value to for linear search: "; cin>>value; //linear search pos = binarySearch(list, value, count, SIZE); if (pos == -1) cout<< "The target "< "; cin>>choice; }while (toupper(choice) == 'Y'); /****************************************************************** This part is for you: You shall follow the above approaches to implement linear search for a list of words. That is, you need to implement the following two functions: (1) binaryWordSearch(...) (2) showWordList(...) and have a similar loop to test your implementation. ******************************************************************/ //well done and exit return 0; }