Question: Write a java program fills in an array with up to 20 nonnegative whole numbers and the searches the array for values specifid by the
Write a java program fills in an array with up to 20 nonnegative whole numbers and the searches the array for values specifid by the user.
I would like to see that you are using binary searsh:
- Implemented by while loop
-implemened by recursion
in the same main
by using this code for while loop:
static int BinarySearch(char target, char array[]) { int low=0, high = 19, middle; while( low<=high) { middle = (low+high)/2; if( array[middle]==target ) return middle; else if( array[middle] and this code for recursion: static int BinarySearch(char target, int low, int high, char[] array) { if( target return -1; int middle = (low+high)/2; if( array[middle]==target ) return middle; else if( array[middle]>target ) return BinarySearch(target, low, middle-1, array); else return BinarySearch(target, middle+1, high, array); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
