What is wrong with my code here?
A Error ./solution.cpp: In function 'int binarySearch(int*, int, int, int)': ./solution.cpp:17:16: error: a function-definition is not allowed here before '{' token int main (void) {
solution.cpp Ⓡ 1 #include<iostream> 2 using namespace std; 3 4 int binarySearch(int A[1000], int p, int r, int num) 5 + { 6 ▾ 23 ▾ 24 7 8 ▾ 9 10 ▾ 11 12 13 14 15 } 16 return -1; 17 int main (void) { 18 int N, num; 19 cin >> N; 20 int A[N]; Y 21 22 - 25 26 27 28 ▾ Y 29 30 31 32 33 34 35 } 36 37 } 38 39 40 if(p <= r) { 11 int mid= (p + r)/2; if(A[mid] == num) return mid; else if(A[mid] > num) return binarySearch(A, p, mid - 1, num); else if(A[mid] < num) return binarySearch(A, mid +1, r, num); for(int i = 0; i < N; i++) { cin >> A } cin >> num; int index = binarySearch (A, 0, N-1, num); if(index == -1) { } else cout << "-1"; cout << index; return 0; Z
What is wrong with my code here?
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am