// RecursiveBinarySearch.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#define N 9
int RecursiveBinarySearch(int A, int low, int high, int x);
int main()
{
int A[N];
int index = 0;
//Put
A[0] = 2;
A[1] = 6;
A[2] = 13;
A[3] = 21;
A[4] = 36;
A[5] = 47;
A[6] = 63;
A[7] = 81;
A[8] = 97;
printf("Elements in Array A\n");
while (index <= 8) {
printf("%d ", A[index]);
index++;
}
printf("\nLocation(index) of element 63\n");
printf("%d", RecursiveBinarySearch(A, 0, 8, 63));
return 0;
}
int RecursiveBinarySearch(int A, int low, int high, int x) {
//Base Condition
if (low > high)
return -1;
int mid = low + (high - low) / 2;
if (x == A[mid])
return mid;
else if (x < A[mid])
return RecursiveBinarySearch(A, low, mid - 1, x);
else
return RecursiveBinarySearch(A, mid + 1, high, x);
}
Here's first problem. Visual studio says int A[9] argument of type "int*" is incompatible with parameter of type "int"
Here's second problem. int mid expression must have pointer-to-object type
I don't know well about pointer so i want to know why this code can't be compiled and how to use pointer in this code.