-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSorting.cs
More file actions
45 lines (39 loc) · 884 Bytes
/
Sorting.cs
File metadata and controls
45 lines (39 loc) · 884 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
37
38
39
40
41
42
using System;
using System.Collections.Generic;
/*
* Insertion Sort : Insertion sort in the similer way as we sort cards in our hand in a card game.
* We assume that the first card is already sorted then, We select an unsorted card.
*
* Insertion sort :
*/
namespace ConsoleApp162
{
internal static class Test
{
public static void Main()
{
int[] data = {9, 5, 1, 4, 3};
InsertionSort(data);
}
private static void InsertionSort(IList<int> data)
{
var len = data.Count;
for (var i = 0; i < len; i++)
{
for (var j = 0; j < len; j++)
{
if (data[i] < data[j])
{
var temp = data[j];
data[j] = data[i];
data[i] = temp;
}
}
}
foreach (var variable in data)
{
Console.WriteLine(variable);
}
}
}
}