-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSort.cs
More file actions
53 lines (50 loc) · 1.45 KB
/
BubbleSort.cs
File metadata and controls
53 lines (50 loc) · 1.45 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataStructureSamples
{
public class Sort_Bubble
{
public static void Main()
{
print();
}
public static void print()
{
int i, j, no, temp;
Console.WriteLine("Enter No of elements : ");
no = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[no];
for (i = 0; i < arr.Length; i++)
{
Console.WriteLine("Enter Data {0} : ", (i + 1));
arr[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("\nBefore Sorting : ");
foreach (int s in arr)
{
Console.Write(s);
}
for (i = 0; i < arr.Length - 1; i++)
{
for (j = 0; j < arr.Length - 1; j++)
{
if (arr[j] > arr[j + 1])
{
temp = arr[j + 1];
arr[j + 1] = arr[j];
arr[j] = temp;
}
}
Console.WriteLine(arr[i]);
}
Console.WriteLine("\nAfter Sorting : ");
foreach (int s in arr)
{
Console.Write(" " + s);
}
}
}
}