Created
July 31, 2012 06:00
-
-
Save JerryBian/3214156 to your computer and use it in GitHub Desktop.
C# code,Insertion Sort
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
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