Solved

# recursive function

Posted on 2003-11-22

Hello, I am a student and I have a problem, I need to rewrite this code so that the function is recursive, but I have no idea where to start, the function is so basic that, to me, the function is fine, here is the code:

#include <iostream>

using std::cin;

using std::cout;

using std::endl;

int linearSearch ( const int [], int, int );

int main ()

{

const int arraySize = 100;

int a [arraySize];

int searchKey;

for ( int i = 0; i < arraySize; i++ )

a[i] = 2 * i;

cout << "Enter integer search key: ";

cin >> searchKey;

int element = linearSearch (a, searchKey, arraySize );

if ( element != -1 )

cout << "Found value in element " << element << endl;

else

cout << "Value not found" << endl;

return 0;

}

int linearSearch ( const int array[], int key, int sizeOfArray )

{

for ( int j = 0; j < sizeOfArray; j++ )

if ( array[j] == key )

return j;

return -1;

}

can any one give me any hints??