R. Clayton (rclayton@monmouth.edu)
(no date)
I did so well describing the array-recursive implementation of find() during
the last lecture that I want to do it again:
static int
find1(int arr[], unsigned i, unsigned n, int x) {
// Return the index of the element in arr[i..n-1] equal to x or -1 if
// there's no such element.
// The empty array.
if (i >= n)
return -1;
// The element.
if (arr[i] == x)
return i;
// The rest of the array.
return find1(arr, i + 1, n, x);
}
See the lecture notes for full details.
This archive was generated by hypermail 2.0b3 on Mon Dec 15 2003 - 19:45:05 EST