-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sorter.cs
33 lines (30 loc) · 811 Bytes
/
Sorter.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
using System;
using System.Collections.Generic;
namespace SelectionSort
{
public static class Sorter
{
public static void SelectionSort<T>(List<T> list) where T : IComparable<T>
{
int n = list.Count;
for (int i = 0; i < n - 1; i++)
{
int minIndex = i;
for (int j = i + 1; j < n; j++)
{
if (list[j].CompareTo(list[minIndex]) < 0)
{
minIndex = j;
}
}
Swap(list, i, minIndex);
}
}
private static void Swap<T>(List<T> list, int i, int j)
{
var temp = list[i];
list[i] = list[j];
list[j] = temp;
}
}
}