Reputation: 21
What type of sorting algorithm is this? It goes through each index, then gets the minimum value in the rest of the array and swaps.
private void Sort(int[] myArray)
{
for (int i = 0; i < myArray.Length; i ++)
{
var minValue = myArray[i];
var minIndex = i;
for(int j = i +1; j< myArray.Length; j++)
{
if (myArray[j] < minValue)
{
minIndex = j;
minValue = myArray[j];
}
}
var temp = myArray[i];
myArray[i] = myArray[minIndex];
myArray[minIndex] = temp;
}
}
Upvotes: 1
Views: 61
Reputation: 2361
It's called Selection sort. As you have already noticed, it selects the minimum element in the remaining list, swaps it in order and repeats until no more elements left.
Upvotes: 2