forked from thuva4/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.cs
More file actions
36 lines (34 loc) · 930 Bytes
/
SelectionSort.cs
File metadata and controls
36 lines (34 loc) · 930 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
33
34
35
36
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace CSharpAlgorithms
{
public class Program
{
public static void Main(string[] args)
{
int[] array={5,3,7,2};
SelectionSort(array);
array.ToList().ForEach(i => Console.WriteLine(i.ToString()));
}
public static void SelectionSort(int[] array)
{
int n=array.Length;
for(int x=0; x<n; x++)
{
int min_index=x;
for(int y=x; y<n; y++)
{
if(array[min_index]>array[y])
{
min_index=y;
}
}
int temp=array[x];
array[x]=array[min_index];
array[min_index]=temp;
}
}
}
}