-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.cs
More file actions
32 lines (29 loc) · 817 Bytes
/
SelectionSort.cs
File metadata and controls
32 lines (29 loc) · 817 Bytes
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
using System;
namespace SortingAlgorithms
{
static partial class Program
{
static void SelectionSort(int[] arr)
{
for (int k = 0; k < arr.Length - 1; k++)
{
int min_index = k;
for (int j = k + 1; j < arr.Length; j++)
{
if (arr[j] < arr[min_index])
{
min_index = j;
}
int temp = arr[min_index];
arr[min_index] = arr[k];
arr[k] = temp;
}
}
Console.WriteLine("\nArray after selection sort:");
for (int i = 0; i < arr.Length; i++)
{
Console.Write(arr[i] + "\t");
}
}
}
}