Skip to content

Instantly share code, notes, and snippets.

@ajinkyakulkarni
Created September 3, 2014 01:34
Show Gist options
  • Save ajinkyakulkarni/06a44d6887c162268c30 to your computer and use it in GitHub Desktop.
Save ajinkyakulkarni/06a44d6887c162268c30 to your computer and use it in GitHub Desktop.
Bubble Sort in C#
using System;
using System.Text;
namespace BubbleSort
{
class Program
{
static void Main(string[] args)
{
int[] A={5,68,11,25,36,2};
int n = A.Length;
for (int i = 0; i<=n - 2; i++)
{
for (int j = 0; j <= n - 2 - i; j++)
{
if (A[j + 1] < A[j])
{
int temp = A[j + 1];
A[j + 1] = A[j];
A[j] = temp;
}
}
}
Console.WriteLine("Sorted array");
for (int k = 0; k < n; k++)
{
Console.WriteLine(A[k]);
}
Console.Read();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment