Beispiel #1
0
//µÝ¹é  
int BinarySearchRecursive(int *array, int low, int high, int key)
{
	if (low > high)
		return -1;
	int mid = low + ((high - low) / 2);

	if (array[mid] == key)
		return mid;
	else if (array[mid] < key)
		return BinarySearchRecursive(array, mid + 1, high, key);
	else
		return BinarySearchRecursive(array, low, mid - 1, key);
}
int main(int argc, char** argv) {
    int size;
    scanf("%d", &size);
    int numbers[size];
    int i;
    for (i = 0; i < size; i++) {
        scanf("%d", &numbers[i]);
    }
    int element;
    scanf("%d", &element);
    //Quicksort(numbers,0,size-1);
    int index = BinarySearchRecursive(numbers,0,size-1,element);
    printf("%d", index);

    return (EXIT_SUCCESS);
}