1
2
3
4
5
6
7
8
9
10
11
12
|
static
void
insertionSort(
int
[] unsorted){
for
(
int
i =
1
; i < unsorted.length; i++) {
if
(unsorted[i -
1
] > unsorted[i]) {
int
temp = unsorted[i];
int
j;
for
(j = i -
1
; j >=
0
&& unsorted[j] > temp; j--) {
unsorted[j +
1
] = unsorted[j];
}
unsorted[j +
1
] = temp;
}
}
}
|
本文转自yeleven 51CTO博客,原文链接:http://blog.51cto.com/11317783/1977371