-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSort.cs
More file actions
33 lines (29 loc) · 846 Bytes
/
BubbleSort.cs
File metadata and controls
33 lines (29 loc) · 846 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
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
public class Bubble_Sort
{
public static void Main(string[] args)
{
int[] a = { 3, 0, 2, 5, -1, 4, 1 };
int t;
Console.WriteLine("Before Sorting:");
foreach (int aa in a)
Console.Write(aa + " ");
for (int p = 0; p <= a.Length - 2; p++) {
for (int i = 0; i <= a.Length - 2; i++) {
if (a[i] > a[i + 1]) {
t = a[i + 1];
a[i + 1] = a[i];
a[i] = t;
}
}
}
Console.WriteLine("\n"+"After Sorting:");
foreach (int aa in a)
Console.Write(aa + " ");
Console.Write("\n");
}
}