Created
September 8, 2014 01:12
-
-
Save ajinkyakulkarni/45ce2ee30841f9e89542 to your computer and use it in GitHub Desktop.
This file contains 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
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