I've been ask to make selection sort code with only recursive method. So i think about making another function to find array that store max value then switch it in my other function.
void p_rec_max(int data[], int cur, int arrSize,int * x) {
if(cur < arrSize - 1) {
if(data[cur] > data[arrSize - 1]) {
*x = cur;
} else if(data[cur] < data[arrSize - 1]){
*x = arrSize - 1;
}
p_rec_max(data,cur + 1,arrSize,&x);
}
}
void rec_selection_sort(int data[], int arrSize) {
if(arrSize > 0) {
int maxi,temp;
p_rec_max(data,0,arrSize,&maxi);
temp = data[arrSize - 1];
data[arrSize - 1] = data[maxi];
data[maxi] = temp;
rec_selection_sort(data,arrSize - 1);
}
}
It got some warning like this
In function 'p_rec_max': warning: passing argument 4 of 'p_rec_max' from incompatible pointer type [enabled by default] note: expected 'int *' but argument is of type 'int **'
And it does not change my array at all. My lack of information of passing pointer in function can't help me to fix that problem. Could you guys fix my code and then explain to me of what is wrong about my code? Thanks