Problem with insertion sort recursively
Can someone tell me what's wrong with the code?
I want to print out the array inside this function as well.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
void insertionSort(double a[],int n){
double tmp;
int i;
if(n==1){
cout<<a[0]<<" ";
return;
}
insertionSort(a,n-1);
tmp = a[n-1];
for(i=n-2;i>=0;i--){
if(a[i]>tmp){
a[i+1]=a[i];
}
}
a[i+1]=tmp;
cout<<a[n-1]<<" ";
return;
}
|
Last edited on
wilson12 wrote: |
---|
Can someone tell me what's wrong with the code? |
It lacks [co
de] tags and is therefore illegible.
Topic archived. No new replies allowed.