1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 |
#include <stdio.h> void insertSort( int
a[], int
n) { int
temp; int
i; for (i = 1; i < n; i++) { temp = a[i]; int
j = i - 1; while (temp < a[j]) { a[j + 1] = a[j]; j--; } a[j + 1] = temp; } } int
main( void ) { int
a[5] = {1,5,4,3,2}; int
i = 0; insertSort(a, 5); for (;i < 5; i++) printf( "%d " , a[i]); printf( "\n" ); } |
原文:http://www.cnblogs.com/xiongge/p/3617516.html