Question: 1. Modify the BinarySearch program given in the textbook (program 4.2.3) so that if the search key is in the array, it returns the largest
1. Modify the BinarySearch program given in the textbook (program 4.2.3) so that if the search key is in the array, it returns the largest index i for which a[i] is equal to key, but, otherwise, returns i where i is the largest index such that a[i] is less than key. It should also be modified to deal with integer arrays rather than string arrays. [MO5.2, MO5.3]
Note: The program should take two command-line arguments, (1) an input file that contains a sorted integer array; and (2) an integer to search for in that array.
- Sample runs would be as follows. >more input.txt 2 3 4 5 6 6 6 7 8 9 11 >java BinarySearch input.txt 10 -9 >java BinarySearch input.txt 6 6
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
