Use indices. A simple binary search will create a variable that points to the middle of the array, if the item being searched for is greater than that element, the middle of the array becomes the low end and a new middle is found:
Code:
int search ( int a[], int key, size_t size )
{
int low = 0,
high = size - 1,
mid;
while ( low <= high ) {
mid = ( high + low ) / 2;
if ( key < a[mid] )
high = mid - 1;
else if ( key > a[mid] )
low = mid;
else
return mid;
}
return NOT_FOUND;
}
The mid variable is what divides the array. Another alternative is to place half of the array in another array and then zero out that half of the original array and perform your operations. Though this is a bit silly since an array is only as big as you tell the compiler when performing operations such as sorting.
-Prelude