Write a complete recursive method called Linear that impleme

Write a complete recursive method called Linear that implements a linear search for an array of ints. Start represents where the call will start within the array, key is the value that is being searched for. Recall that a linear search returns the index where the key was found if successful, otherwise it returns -1. the initial call will pass 0 for start.

public static int Linear(int[] a, int start, int key) {

.

.

}

Solution

public static int Linear(int[] a, int start, int key) {
  
if(start>=a.length)
return -1;
  
if(key==a[start])
return start;
  
return Linear(a,start+1,key);
}

Write a complete recursive method called Linear that implements a linear search for an array of ints. Start represents where the call will start within the arra

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site