Skip to content

Instantly share code, notes, and snippets.

@ajinkyakulkarni
Created September 8, 2014 01:12
Show Gist options
  • Save ajinkyakulkarni/45ce2ee30841f9e89542 to your computer and use it in GitHub Desktop.
Save ajinkyakulkarni/45ce2ee30841f9e89542 to your computer and use it in GitHub Desktop.
using System;
using System.Text;
namespace InsertionSort
{
class Program
{
static void Main(string[] args)
{
int[] A = { 5, 68, 11, 25, 36, 2 };
int n=A.Length;
for (int i = 1; i <= n - 1; i++)
{
int v = A[i];
int j = i - 1;
while (j >= 0 && A[j] > v)
{
A[j + 1] = A[j];
j = j - 1;
}
A[j + 1] = v;
}
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