-
Notifications
You must be signed in to change notification settings - Fork 18
/
Bubble Sort for Ascending Order.cs
51 lines (48 loc) · 1.4 KB
/
Bubble Sort for Ascending Order.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
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication56
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Sorting an Array in Ascending Order like Bubble Short");
int i,temp=0,j, N,min=0;
Console.WriteLine("Enter the N Range of the Array");
N = Convert.ToInt32(Console.ReadLine());
int[] a = new int[N];
Console.WriteLine("Enter the Values");
for (i = 0; i < N; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("The Values Are:");
for (i = 0; i < N; i++)
{
Console.Write("{0} ", a[i]);
}
Console.WriteLine("\n");
for (i = 0; i < N; i++)
{
for (j = 0; j < N - 1; j++)
{
if (a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
Console.WriteLine("After the values sorted");
for (i = 0; i < N; i++)
{
Console.Write("{0} ", a[i]);
}
Console.ReadLine();
}
}
}