How do I divide an array. In my book there is nothing about dividing up an array. I just need that part the rest I can figure out. It for dividing up an array and then putting it back together sorted. Can anyone help. THanx......................

Printable View

- 06-13-2002Unregistereddivide and conquer
How do I divide an array. In my book there is nothing about dividing up an array. I just need that part the rest I can figure out. It for dividing up an array and then putting it back together sorted. Can anyone help. THanx......................

- 06-13-2002Prelude
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;

}

-Prelude