recursive function to implement the Sequential (linear) Search Algorithm. The fnction should take as paramaters: an array of integers (Array), an integer value (Key), and two integers (First and Last) representing the first index and the last index of the array. The function should sequentially search and return the position of the first occurrence of Key in the array. If Key does not exist in the array, the function should return -1. The function protoype is:
int LinearSearch(int Array[ ], int Key, int First, int Last
الحل
PHP:
int LinearSearch(int array[],int key,int first,int last){
if (first>last)
return -1;
else {
if(array[first]==key)
return first;
return LinearSearch(array,key,first+1,last);
}
}
نسألكم الدعاء