Skip to content

Commit 290dc06

Browse files
authored
Merge pull request argonautica#54 from CelineLind/master
Added C# folder and BubbleSort.cs
2 parents 2e4d13b + 4ddeed8 commit 290dc06

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

C#/BubbleSort.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Bubble Sort with C#
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+
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ _Sorting algorithms implemented in different languages (for hacktoberfest 😃).
2525
- [Quick Sort](C/QuickSort.c)
2626
- [Selection Sort](C/SelectionSort.c)
2727

28+
### C#
29+
- [Bubble Sort](C#/BubbleSort.cs)
30+
2831
### Go
2932
- [Radix Sort](Go/RadixSort.go)
3033

0 commit comments

Comments
 (0)