-
Notifications
You must be signed in to change notification settings - Fork 0
/
SelectionSort.cs
49 lines (40 loc) · 1.13 KB
/
SelectionSort.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
namespace Variables
{
class Program{
static void Main(string[] args)
{
int[] arr = { 15,-41,-5,-9,0,156,-63,-85,66,95,35,14,1616 };
Solution solution = new Solution();
solution.sort(arr);
Console.WriteLine("Sorted array is : ");
solution.printArray(arr);
}
}
public class Solution
{
public Array sort(int[] arr)
{
for (var i = 0; i < arr.Length-1; i++)
{
var SmallestIdex = i;
for (var j = i + 1; j < arr.Length; j++)
{
if (arr[j] < arr[SmallestIdex])
SmallestIdex = j;
}
var temp = arr[SmallestIdex];
arr[SmallestIdex] = arr[i];
arr[i] = temp;
}
return arr;
}
public Array printArray(int[] arr)
{
for (int i = 0; i < arr.Length; ++i)
Console.Write(arr[i] + " ");
Console.WriteLine();
return arr;
}
}
}