Skip to content

Instantly share code, notes, and snippets.

@JerryBian
Created July 31, 2012 06:00
Show Gist options
  • Save JerryBian/3214156 to your computer and use it in GitHub Desktop.
Save JerryBian/3214156 to your computer and use it in GitHub Desktop.
C# code,Insertion Sort
internal class Program
{
private static void Main(string[] args)
{
int[] num = { 69, 56, 77, 44, 8, 0, 111, 566 };
for (int i = 1; i < num.Length; i++)
{
int key = num[i];
int j = i - 1;
while (j >= 0 && num[j] > key)
{
//loop
num[j + 1] = num[j];
j--;
}
num[j + 1] = key;
}
//display
foreach (var item in num)
{
Console.WriteLine(item);
}
Console.ReadKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment