N
N
NQUARE2020-10-23 08:39:43
C++ / C#
NQUARE, 2020-10-23 08:39:43

How to remake the insertion sort function in descending order?

Good morning.

How can I modify this insertion sort function so that it sorts in descending order?

void insort(int* l, int* r) {
    for (int *i = l + 1; i < r; i++) {
        int* j = i;
        while (j > l && *(j - 1) > *j) {
            swap(*(j - 1), *j);
            j--;
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2020-10-23
@NQUARE

Change < to > where you compare elements. Hint: you have an array passed by two int pointers. Those. the elements themselves are where you dereference some pointers (this is the *something operation).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question