commit cd09f71836d10706ec13d6ca676c0f47d5df5aef
parent 8eb0291e79c709c44aa7b34ffeada097f3829d68
Author: mjkloeckner <martin.cachari@gmail.com>
Date: Mon, 17 Oct 2022 19:26:21 -0300
Updated merge_sort and selection_sort
Now merge_sort and selection_sort show against which iten on the array
are comparing, or atleast (on merge sort) an aproximation to look better
Diffstat:
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/sort.c b/sort.c
@@ -150,6 +150,7 @@ void merge(SAV *sav, int low, int middle, int high) {
/* merge B and C in order */
for(k = low, i = j = 0; (k < high) && (i < n1) && (j < n2); k++) {
+ sav->cmp = middle + j;
if(B[i] <= C[j]) {
sav->arr->v[k] = B[i++];
sav->cmps += 1;
@@ -307,9 +308,11 @@ void selection_sort(SAV *sav)
min = i;
for (j = i + 1; j < sav->arr->len; j++) {
sav->sel = j;
- if (sav->arr->v[j] < sav->arr->v[min]) min = j;
+ if (sav->arr->v[j] < sav->arr->v[min]) {
+ min = j;
+ sav->cmp = min;
+ }
sav->cmps += 1;
- sav->cmp = j;
if(sort_delay(sav) == STOP) return;
if(sort_pause(sav) == STOP) return;
}