/***************************************************************************** * Creates a random array of ints, and searches for a random int * * using the binary search. * * Inputed: * * Outputed: mainarray, search_int * * Written: August 06, 2002 * * By: Ronald Roberts * *****************************************************************************/ /* ***************NOTE*************** THE BINARY SEARCH ALGORITHM HAS BEEN RENAMED TO "BINARY_SEARCH_0" BECAUSE OF A NAMING CONFILCT WITH A BUILT IN FUNCTION DEFINITION. ********************************** */ /* Compiler Directives */ #include #include #include #include #include /* Bubble Sort Algorithm */ void bubble_sort_ascending (int array[], int arrayLength); void bubble_sort_ascending (int array[], int arrayLength) { int i, j, flag=1; int temp; for (i=1; (i<=arrayLength) && flag; i++) { flag =0; for (j=0; j< (arrayLength - i); j++) { if (array[j+1] < array [j]) { temp=array[j+1]; array[j+1]=array[j]; array[j]=temp; flag=1; } } } } /* Random Number Function */ double randomfunction(int modulator, double shifter); double randomfunction(int modulator, double shifter) { return rand()%modulator+shifter; } /* Binary Search Algorithm */ void binary_search_0(int x[], int lowerbound, int upperbound, int search_num); void binary_search_0(int x[], int lowerbound, int upperbound, int search_num) { int search_pos; int compare_count=1; search_pos=(lowerbound+upperbound)/2; while((x[search_pos] !=search_num) && (lowerbound <= upperbound)) { compare_count++; if (x[search_pos] > search_num) { upperbound=search_pos-1; } else { lowerbound=search_pos+1; } search_pos=(lowerbound+upperbound)/2; } if (lowerbound <= upperbound) { cout<<"A binary search found the number in "<