forked from MakeContributions/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubble-sort.cs
31 lines (29 loc) · 833 Bytes
/
bubble-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
using System;
namespace Algorithms.Sorts
{
public class BubbleSort
{
public static void Main()
{
int[] arr = { 800, 11, 50, 771, 649, 770, 240, 9 };
Sort(arr);
var result = string.Join(" ", arr);
Console.WriteLine(result);
}
public static void Sort(int[] source)
{
for (int write = 0; write < source.Length; write++)
{
for (int sort = 0; sort < source.Length - 1; sort++)
{
if (source[sort] > source[sort + 1])
{
var temp = source[sort + 1];
source[sort + 1] = source[sort];
source[sort] = temp;
}
}
}
}
}
}