im designing a program where it calls a function that uses the linear search algorithm to locate one of the values.
function must keep a count of the comparisons it makes until it finds the value. the program then calls the binary search (a sep. function) to locate the same value-and it should keep a count of the comparisons as well. all of this should be displayed on the screen
sample output:
Original Array: (show 36 random values between 0 and 4999 inclusive-cannot be duplicates)
3224 1903 286
2660 2122 1310
667 789 503 etc.....
Test values:
3234 2660 667 1501 1201
Linear Search Version -Before Sort:
Test Value Result Number of Comparisons
3234 found 1
2660 found 13
667 found 25
//Show average number of comparisons for successfuls searches
//Show average number of comparisons for unsuccessfuls searches
Sorted Array
//show sorted array
Linear Search - AFTER sort:
//show AFTER sort
Binary Search
//show
i wrote a layout for my functions and this is what i have:
//function prototypes
void fillMainList(int list[]);
//this will fill main list array with random numbers from 0 to 4999 inclusive-there will be NO duplicates (so i must get a rand number and check if it is not in the array already and insert and increment-if it is-i should loop again and test a new number
void TestArray(const int list[], int test[]);
//take main list and put some values in the test array and fill test array with additional random numbers. this will take every 12th element from main list and put it into test value array (ex 0, 12, 24, 36, etc) rest of the array will be filled with random numbers from 0 to 4999 so there are no duplicates in the test value
void PrintArray(const int ary[], int size);
//will print an array on the screen with 12 numbers per row [use setw(6)]. function should know the size of the array before it can print both the main list and the test value
void selectionSort(int list[], int size);
//sort main list array with selection sort
int LinearSearch(const int list[], int value, int& comps);
//searches array for the value with linear search and counts number of comparisons. position of value is found or -1 is returned.
int BinarySearch(const int list[], int value, int& comps);
//searches for value using binary search and counts the number of comparisons. postition of value is found or -1 is returned.
i am able to write a plan for this program but now i dont know how to convert all this writing to code. i need help-so i dont confuse or make it complicated even more so i could use some pointers to guide me. and i also cant find the sorting code in the book-does anyone happen to know it?
thanks! :)