Assignment 9
Write a program which encodes each of the three ordered list searches (linear, quadratic, and binary) as a function. Write an initialization procedure to set up the following array, by reading in the values from an input file. The main program should consist of a loop which allows the user to enter a number to be searched for and then runs each of the searches to find it.
Modify the search functions so that they count the total number of elements of the array which are inspected during the search (that is, the number of comparisons performed). You should use an output parameter (call-by-reference) to relay this information back to the main program. After each sequence of searches, the user should be given the option of continuing (searching for another number) or quitting the program.
The array:
3 8 11 14 16 21 23 27 35 37 53 64 66 67 83 83 89 93 125 184
Please submit a printed copy of your code, plus either your program on disk or a printed sample run in which you search for the following elements:
27 21 1 72 200 125 83 37
A program run might look like this:
Please enter a number to search for: 27
Linear search: Number found at position 8, inspected 8 elements.
Quadratic search: Number found at position 8, inspected 5 elements.
Binary search: Number found at position 8, inspected 4 elements.
Would you like to search for another number (y/n) ? y
Please enter a number to search for: 1
Linear search: Number not found, inspected 1 element.
Quadratic search: Number not found, inspected 2 elements.
Binary search: Number not found, inspected 5 elements.
Would you like to search for another number (y/n) ? n