So here's my code. It's telling me that partition isn't declared when I call it in kSmall... Any ideas?
int kSmall(int A[], int k, int low, int high){
int pivot = A[(low+high)/2];
int idx = partition(A, pivot, low, high);
if(idx-low+1>k)
kSmall(A,k,low,idx-1);
else if(idx-low+1<k)
kSmall(A,k,idx+1,high);
else
return A[idx];
}
int partition(int A[], int p, int low, int high){
int temp;
int left = low;
int right = high;
while (left < right){
while (A[left]<p)
left++;
while (A[right]>p)
right--;
if (left<right){
temp = A[left];
A[left] = A[right];
A[right] = temp;
}
}
return left;
}
The exact error is: main.cpp:36:43: error: ‘partFunc’ was not declared in this scope
Aucun commentaire:
Enregistrer un commentaire