What algorithm is this?

I can not understand this particular algorithm. It seems to be bubblesort, but not in the traditional sense. What is it?

public static void main(String[] args) 
{
    double[] a = {0.75, 0.5, 1.0};                          
    sort(a);

    for (int i = 0; i < a.length; i++)
        System.out.println(a[i]);
}

public static void sort(double[] tal)
{
    double p = 0;
    int k = 0;

    for (int i = 0; i < tal.length - 1; i++)
    {
        k = i;
        for (int j = i + 1; j < tal.length; j++)
        {
            if (tal[j] < tal[k])
                k = j;
        }

        p = tal[i];
        tal[i] = tal[k];
        tal[k] = p;
    }
}
+4
source share
3 answers

At first, I thought incorrectly that this was Insertion sort . This is a sorting selection (from a Wikipedia entry)

Selection sort

+23
source

This is a sort of selection. The inner loop finds the smallest among the remaining elements, which then exchanges with the first element in the unsorted range.

+5
source

. for while.

+2

Source: https://habr.com/ru/post/1523533/


All Articles