I cannot seem to make sense of this particular algorithm. It seems to be a bubblesort
but not in a 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;
}
}
At first, I incorrectly thought it an Insertion sort. It is a Selection sort (from the Wikipedia entry)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With