Weird output of merge sort for no. of entries not being a power of 2. - c
问题 I have written a code for mergesort to sort an array of structures in c it works fine when i give no. of entries as a power of 2 but does not even sort the records for other no. of entries. I Would like to learn where is my logic going wrong?? Here is my code: void Mergesort(struct record r[],int n) { int k; if(n>1) { int i,j; struct record r1[n/2]; struct record r2[n-n/2]; for(i=0,j=n/2;i<n/2 && j<n;i++,j++) { r1[i]=r[i]; r2[i]=r[j]; } Mergesort(r1,n/2); Mergesort(r2,n/2); r=Merge(r1,r2,r,n)