Sunday 15 June 2014

c - Bubble sort all but first spot -



c - Bubble sort all but first spot -

if alter status (i < n -1) (i < n) glitches, , now, first position [0] gets sorted.

int sortindexbydate(match match[], int n) { int i, j, sum[n], swapped; (i = 0; < n; i++) sum[i] = match[i].d.year*10000 + match[i].d.month*100 + match[i].d.day; { swapped = false; (i = 1; < n - 1; i++) { if (sum[i] < sum[i + 1]) { swapint(&sum[i], &sum[i+1]); swapmatch(&match[i], &match[i+1]); swapped = true; } } n--; } while (swapped); }

you starting @ i = 1 in inner loop. hence sum[0] beingness ignored.

change

for (i = 0; < n-1; i++) {

c bubble-sort sorted

No comments:

Post a Comment