Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "Proto.h"
- int binarySearch(char * nums, char svalue, int start, int end)
- {
- middle = (start + end) / 2;
- /* Target found */
- if (nums[middle] == svalue)
- {
- return middle;
- }
- /* Target not in list */
- else if( start == end )
- {
- return -1;
- }
- /* Search to the left */
- else if( nums[middle] > svalue )
- {
- count++;
- return binarySearch( nums, svalue, start, (middle-1) );
- }
- /* Search to the right */
- else if( nums[middle] < svalue )
- {
- count++;
- return binarySearch( nums, svalue, (middle+1), end );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement