// ***************************************************************** // Author: Zhixiang Chen // Class: CSCI/CMPE 1170, Spring 2009 // Lab 23: Header file for Lab 23 // Date: January 12, 2009 // Comment: The code here is meant to be revised. // ***************************************************************** #include #include #include #include #include using namespace std; #ifndef LAB_23_HEAD_H #define LAB_23_HEAD_H /*********************************************************************** This function does linear search to see if the target vaule is in the list or not. If yes, it returns the position of the target in the list otherwise it returns -1. Note: count is an output paramter to record the number of comparisons during the search ***********************************************************************/ int binarySearch(const int list[], const int value, int & count, const int SIZE) { //working vars int first =0, //beginning of the search range last = SIZE-1, //end of the search range; middle, //middle of the search range pos = -1; //position for the target or -1 if not in the list bool found =false; //flag for being found //set initial value for count count = 0; while (!found && first <=last) { count++; //count comparisons middle =(first + last)/2; //middle range for binary division if(list[middle]==value) //found { found = true; pos = middle; } else if (list[middle] > value) //search the left half last = middle - 1; else //search the right half first = middle + 1; } return pos; } /************************************************************************ this function print all numbers in the list. ************************************************************************/ void showList(const int list[], const int SIZE) { cout<<"The list is ..... " <