This is my problem...hopefully somebody can help me out with this.
This is what I am supposed to be doing:
Recursive Binary Search of 2-dimensional array:
Load a 30x20 two-dimensional array of ints with values from the file “values.txt”. The file contains 900 numbers in order. Once the array is loaded, allow the user to select a number to find in the array. Call a recursive routine that searches for the number, then display the entire array and the location of the number, if found. If the number is not found, display the array and notify the user that the number was not found. The user must be able to select numbers to find until they wish to quit.
Recursive Search Details: This search must be done in two steps, both are recursive. First, narrow the search to the row where the item must be located. Second, search that row for the item. You may use one recursive function or, if you wish, you may use two recursive routines, one that handles the first step and then calls another that handles the second step. In any case, you must return a Boolean value that indicates the success or failure of the search, and you must use call-by-reference parameters to store the location of the item if found. If the number is not found, these parameters need not be changed.
This is what I have so far:
int rBinarySearch(int Values[][20], int first, int last, int key)
{
first = Values[0][0];
last = Values[29][19];
if(first <= last)
{
int mid = (first + last) / 2;
}
if(key == Values[][mid])
{
return (mid);
}else if(key < Values[][mid])
{
return rBinarySearch(Values, first, mid-1, key);
}else
{
return rBinarySearch(Values, mid+1, last, key);
}
return false;
}
for some reason when I compile I get errors about illegal if elses...don't know if my spacing is off or what but I played around with it for a while. Also how do I display the location of the number if found when I display the array and is the rest correct in my coding? Also how do I return a bool if not found when I have to return (first +1)? Am I on the right track and what am I doing wrong/ how do I fix it? Any help would be greatly appreciated.