次のエラーが表示されます。
prog.cpp:1:5: error: expected unqualified-id before ‘[’ token
次のコードを作成します。
int [] quick_srt(int array[], int low, int n){
それが問題ですよね?
編集
int [] quick_srt(int array[], int low, int n){
int lo = low;
int hi = n;
comp++;
if (lo >= n){ // lo is greater then or equal to n
return array;
}
int mid = array[(lo + hi) / 2]; //Using mid as pivot
comp++;
while (lo < hi){ //lo is less then hi
comp++;
while (lo < hi && array[lo] < mid){ //lo less than hi AND array[lo] less than mid
lo++;
comp++;
}
comp++;
while (lo < hi && array[hi] > mid) {//lo less than hi AND array[lo] greater than mid
hi--;
comp++;
}
comp++; //for if
comp++; //for else
if(array[lo] == array[hi]){
break; //for duplicate items
}
else if (lo < hi) { // less than
int T = array[lo];
array[lo] = array[hi];
array[hi] = T;
swaps++;
}
comp++;
}
comp++;
if (hi < lo) { //hi is less than lo
int T = hi;
hi = lo;
lo = T;
}
quick_srt(array, low, lo); //recrusie call
quick_srt(array, lo == low ? lo+1 : lo, n); //re-call, if lo = low, increment lo else pass lo and n
return array;
}