forked from Qwardly/HelloGit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
35 lines (31 loc) · 989 Bytes
/
Program.cs
File metadata and controls
35 lines (31 loc) · 989 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
using System;
using System.Linq;
namespace HelloGit
{
internal static class Program
{
public static void Main(string[] args)
{
var initialArray = new[] {1, 5, 3, 2, 5, 6};
var sortedArray = new[] {1, 2, 3, 5, 5, 6};
BubbleSort(initialArray);
if (!initialArray.SequenceEqual(sortedArray)) throw new Exception("Sorting doesn't work!");
Console.WriteLine("complete!");
}
private static void BubbleSort(int[] initalArray)
{
for (int i = 0; i < initalArray.Length-1; i++)
{
for (var j = i+1; j < initalArray.Length; j++)
{
if (initalArray[i] > initalArray[j])
{
var t = initalArray[i];
initalArray[i] = initalArray[j];
initalArray[j] = t;
}
}
}
}
}
}