Created
April 3, 2013 17:43
-
-
Save nanchenzi/5303460 to your computer and use it in GitHub Desktop.
插入排序
This file contains hidden or 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
int[] InsertionSort(int[] array){ | |
for(int i = 1; i<array.length; i++){ | |
int insertValue = array[i]; | |
int cursor = i-1; | |
while(cursor >= 0 && array[cursor]>insertValue){ | |
array[cursor+1] = array[cursor]; | |
cursor--; | |
} | |
array[cursor+1] = insertValue; | |
} | |
return array; | |
} | |
/**在最优的情况下,它的算法时间复杂度为o(n),在最坏的情况下算法时间复杂度为o(n^2) **/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment