I was looking to create a function that takes in 2 arguments, an array and a key value, and recursively checks values of the array to see if they match the key.
To accomplish this, I need to check if the array is empty. I also need a way to call the array in my recursive function. I couldn't find anything on stack overflow to help, but I tried the method suggested in this Check if list is empty in C# post, and the code gave an error.
TLDR Need to figure out how to check if array is empty, and how to make recursive calls to a function that accepts an array as a parameter.
// recursive method: increment count for each recursive call; return the value of count when the key matches the value, then decrement count on
int Search::ReKeySearch( int arr[], int key){
//bool isEmpty = !list.Any(); tried to use this code, found on StackExchange, gave following error: "Cannot refer to class template 'list' without a template argument list"
if ( arr[count] == 0 ){ //if the key matches the list index's value
store = count; // so that I can reset count to zero, I use a storing variable
count = 0; // count should always be zero on exiting or entering a function
return store;
}
else{
count++;
if ( /*need to check if list is empty*/ ){
ReKeySearch(arr[1:], key); //recursive call to function on list after zeroth member
//returns error "expected ']'", pointing to the colon
}// using pointer to attack problem of list index
else
;
count--;
}
if (count == 0)
return -1;
}