/* bad example,mixed return types */ /*----------------------------------------------*/ /* Function search */ /* INPUT: */ /* a[] an array of integers */ /* n: the size of the array */ /* key: an integer representing the */ /* key to be searched for */ /* OUTPUT : an integer that indicates the */ /* position of the key in the array */ /* if the key is found */ /* -1 is returned if the key is */ /* not in the array */ /* METHOD : binary search technique */ /*----------------------------------------------*/ int search(int a[],int n,int key) { int low = 0, mid, high = n -1 ; while (low <= high) {mid = (low + high ) /2; if (key < a[mid]) high = mid - 1; else if (key > a[mid]) low = mid + 1; else /* key found */ return mid ; } /* we get here if low > high and key is not in the array*/ /* software design error - no return value */ printf("key not found\n"); }