Created
November 20, 2019 04:19
-
-
Save aabir/d0a5e609788d6c4cec77431d825bfaff to your computer and use it in GitHub Desktop.
Selection Sort in C#
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; | |
namespace SelectionSort | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int[] inputAry = new int[] { 39, 12, 33, 68, 44 }; | |
int aryLen = inputAry.Length; | |
int min; | |
for (int i = 0; i < aryLen; i++) | |
{ | |
min = i; | |
for (int j = i + 1; j < aryLen; j++) | |
{ | |
if(inputAry[j] < inputAry[min]) | |
{ | |
min = j; | |
} | |
} | |
if (min != i) | |
{ | |
var temp = inputAry[i]; | |
inputAry[i] = inputAry[min]; | |
inputAry[min] = temp; | |
} | |
} | |
for(int i = 0; i < inputAry.Length; i++) | |
{ | |
Console.WriteLine(inputAry[i] + " "); | |
} | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment