forked from jainaman224/Algo_Ds_Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Selection_Sort.cs
41 lines (34 loc) · 1 KB
/
Selection_Sort.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Selection_Sort
{
class Program
{
/// Function for selection sort
static void Selection_Sort(int[] array, int size)
{
int min_index, temp;
for(int i = 0; i < size - 1; i++)
{
min_index = i;
for(int j = i + 1; j < size; j++)
if(array[j] < array[min_index])
min_index = j;
temp = array[i];
array[i] = array[min_index];
array[min_index] = temp;
}
}
static void Main(string[] args)
{
int[] array = {2, 4, 3, 1, 6, 8, 4};
Selection_Sort(array, 7);
for (int k = 0; k < 7;k++ )
Console.Write(array[k]+" ");
Console.ReadLine();
}
}
}