find largest in array with recrusion
Wrote this one to find largest integer in one dimensional array. It has to be done without global or local variables; only indexes of start & end + array itself.
Cannot get reasonable output & I'm not sure I have the right concept here, of using compression between array[pntrA] and *(++array).
Code:
int largest(int *array, int pntrA, int pntrB)
{
if (pntrA==pntrB)
return array[pntrA];
else
if (pntrA<pntrB)
{
if (array[pntrA]<*(++array))
{
pntrA++;
return largest(array, pntrA, pntrB);
}
else
{
*(++array)=array[pntrA];
pntrA++;
return largest(array, pntrA, pntrB);
}
}
return 0;
}
Help will be highly appreciated