You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1006 B
C#

/*
* C# Program to Perform Bubble Sort
*/
using System;
class bubblesort
{
static void Main(string[] args)
{
int[] a = { 3, 2, 5, 4, 1 };
int t;
Console.WriteLine("The Array is : ");
for (int i = 0; i < a.Length; i++)
{
Console.WriteLine(a[i]);
}
for (int j = 0; j <= a.Length - 2; j++)
{
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("The Sorted Array :");
foreach (int aray in a)
Console.Write(aray + " ");
Console.ReadLine();
}
}
/*
The Array is :
3
2
5
4
1
The Sorted Array :
1
2
3
4
5