last index using recursion code example
Example 1: last index of a number using recursion
int rLookupAr (int array[], int size, int target)
{
if(size<=0) return -1;
if(array[size-1] == target)
return size-1;
else
return rLookupAr (array, size-1, target); //recurse
}
Example 2: last index of a number using recursion
int rLookupAr(int array[], int size, int target)
{
if(size < 1) return -1;
size--;
if(array[size] == target) return size;
return rLookupAr(array, size,target);
}