Skip to content

Instantly share code, notes, and snippets.

@diman82
Created March 22, 2017 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diman82/76ef99f2a67c6c81cf09a8b9b4bd047c to your computer and use it in GitHub Desktop.
Save diman82/76ef99f2a67c6c81cf09a8b9b4bd047c to your computer and use it in GitHub Desktop.
C# Bubble sort implementation
/*
* 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