Created
June 25, 2020 02:12
-
-
Save AbhinavPradeep/39372f7ea0e3eed28c4d2b7a4e1bb655 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
namespace SortingArrays | |
{ | |
class SelectionSort | |
{ | |
public void Sort(int[] input) | |
{ | |
var watch = Stopwatch.StartNew(); | |
try | |
{ | |
int smallestIndex; | |
for (int i = 0; i < input.Length - 1; i++) | |
{ | |
smallestIndex = i; | |
for (int currentIndex = i + 1; currentIndex < input.Length; currentIndex++) | |
{ | |
if (input[currentIndex] < input[smallestIndex]) | |
{ | |
smallestIndex = currentIndex; | |
} | |
} | |
int TemporaryVariable = input[i]; | |
input[i] = input[smallestIndex]; | |
input[smallestIndex] = TemporaryVariable; | |
} | |
watch.Stop(); | |
} | |
finally | |
{ | |
PrintArray printArray = new PrintArray(); | |
printArray.PrintIntegerArray(input); | |
Console.WriteLine($" Selection Sort executed in {watch.ElapsedTicks} ticks"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment