-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path03 ● BubbleSort.cs
44 lines (43 loc) · 1.15 KB
/
03 ● BubbleSort.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
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
namespace Bubble_Sort
{
class Program
{
public void Sort(int[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
for (int j = 0; j < arr.Length-1; j++)
{
if (arr[j] > arr[j+1])
{
int temp = arr[j+1];
arr[j+1] = arr[j];
arr[j] = temp;
}
}
}
}
public void Print(int[]arr)
{
for (int i = 0; i < arr.Length; i++)
{
Console.Write(arr[i] + " ");
}
}
static void Main(string[] args)
{
Console.WriteLine("Enter the size of array : ");
int x = int.Parse(Console.ReadLine());
int[] arr = new int[x];
for (int i = 0; i < x; i++)
{
Console.WriteLine("Enter the {0} element : ", i);
arr[i] = int.Parse(Console.ReadLine());
}
Program S = new Program();
S.Sort(arr);
S.Print(arr);
}
}
}