Created
March 22, 2017 22:25
-
-
Save diman82/76ef99f2a67c6c81cf09a8b9b4bd047c to your computer and use it in GitHub Desktop.
C# Bubble sort implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* C# Program to Perform Bubble Sort | |
*/ | |
using System; | |
class bubblesort | |
{ | |
static void Main(string[] args) | |
{ | |
int[] a = new int[100]; | |
Random rand = new Random(); | |
for (int i = 0; i < a.Length; i++) | |
{ | |
a[i] = rand.Next(1,a.Length); | |
} | |
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.ToString() + " "); | |
Console.ReadLine(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment