sorting-visualization/SortingVisualization/Algorithms/Selectionsort.cs

21 lines
763 B
C#
Raw Permalink Normal View History

namespace SortingVisualization.Algorithms {
public class Selectionsort : SortingAlgorithm {
public override string GetAlgorithmName() => "Selectionsort";
public override void Sort(ref DataSet set) {
Simulate(ref set);
System.Console.WriteLine("Doing {0}...", this.GetAlgorithmName());
for (int i = 0; i < set.Size; i++) {
int min = i;
for (int j = i + 1; j < set.Size; j++)
if (set.LessThan(j, min))
min = j;
set.Swap(min, i);
}
System.Console.WriteLine("{0} complete!", this.GetAlgorithmName());
if (!set.SimulateMode)
set.FinalizeVideo();
}
}
}