Skip to content

Commit b89ceb1

Browse files
authored
Update BubbleSort.cs
completed bubble sort in c#
1 parent 341c26c commit b89ceb1

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

C#/BubbleSort.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,34 @@
11
// Bubble Sort with C#
2-
// to be continued by me later
2+
using System;
3+
4+
namespace BubbleSort
5+
{
6+
class MainClass
7+
{
8+
public static void Main()
9+
{
10+
// test numbers to sort
11+
int[] toSort = { 5, 2, 6, 8, 3};
12+
13+
// perform bubble sort
14+
for (int i = 0; i < 5; i++)
15+
{
16+
for (int j = 0; j < 4; j++)
17+
{
18+
if (toSort[j] > toSort[j + 1])
19+
{
20+
int temp = toSort[j];
21+
toSort[j] = toSort[j + 1];
22+
toSort[j + 1] = temp;
23+
}
24+
}
25+
}
26+
27+
// print to console results
28+
for (int i = 0; i < 5; i++)
29+
{
30+
Console.WriteLine(toSort[i]);
31+
}
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)