N
N
NQUARE2020-10-18 18:56:22
C++ / C#
NQUARE, 2020-10-18 18:56:22

What is this function?

What is this C++ function? What is the name of the algorithm?

void SortArr(int arr[], int n) {
    for (int startIndex = 0; startIndex < n - 1; ++startIndex) {
        int smallestIndex = startIndex;
        for (int currentIndex = startIndex + 1; currentIndex < n; ++currentIndex) {
            if (arr[currentIndex] < arr[smallestIndex]) {
                smallestIndex = currentIndex;
            }
        }
        swap(arr[startIndex], arr[smallestIndex]);
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2020-10-18
@0xD34F

Read the descriptions of the algorithms , look for the one that matches the code shown.

O
olkhovichs, 2020-10-18
@olkhovichs

Selection sort

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question