这里是代码,这是通过Insert Code for Windows Live Writer.msi这个插件发布的:
1: #include <stdio.h>
2:
3: #define LEN 5
4: int a[LEN] = { 10, 5, 2, 4, 7 };
5:
6: void insertion_sort(void)
7: {
8: int i, j, key;
9: for (j = 1; j < LEN; j++) {
10: printf("%d, %d, %d, %d, %d\n",
11: a[0], a[1], a[2], a[3], a[4]);
12: key = a[j];
13: i = j - 1;
14: while (i >= 0 && a[i] > key) {
15: a[i+1] = a[i];
16: i--;
17: }
18: a[i+1] = key;
19: }
20: printf("%d, %d, %d, %d, %d\n",
21: a[0], a[1], a[2], a[3], a[4]);
22: }
23:
24: int main(void)
25: {
26: insertion_sort();
27: return 0;
28: }
好了,不知道这次怎么样?希望没有什么问题
下面的代码是通过Code Snippet plugin for Windows Live Writer这个插件发布的:
#include <stdio.h>
#define LEN 5
int a[LEN] = { 10, 5, 2, 4, 7 };
void insertion_sort(void)
{
int i, j, key;
for (j = 1; j < LEN; j++) {
printf("%d, %d, %d, %d, %d\n",
a[0], a[1], a[2], a[3], a[4]);
key = a[j];
i = j - 1;
while (i >= 0 && a[i] > key) {
a[i+1] = a[i];
i--;
}
a[i+1] = key;
}
printf("%d, %d, %d, %d, %d\n",
a[0], a[1], a[2], a[3], a[4]);
}
int main(void)
{
insertion_sort();
return 0;
}
下面的代码和上面的一样,只不过不使用容器,使用代码行:
1: #include <stdio.h>
2:
3: #define LEN 5
4: int a[LEN] = { 10, 5, 2, 4, 7 };
5:
6: void insertion_sort(void)
7: {
8: int i, j, key;
9: for (j = 1; j < LEN; j++) {
10: printf("%d, %d, %d, %d, %d\n",
11: a[0], a[1], a[2], a[3], a[4]);
12: key = a[j];
13: i = j - 1;
14: while (i >= 0 && a[i] > key) {
15: a[i+1] = a[i];
16: i--;
17: }
18: a[i+1] = key;
19: }
20: printf("%d, %d, %d, %d, %d\n",
21: a[0], a[1], a[2], a[3], a[4]);
22: }
23:
24: int main(void)
25: {
26: insertion_sort();
27: return 0;
28: }
下面使用“代码插入插件”cf.SyntaxHighighter测试一下:
下面使用Paste from Visual Studio来试一试:
#include <stdio.h> #define LEN 5 int a[LEN] = { 10, 5, 2, 4, 7 }; void insertion_sort(void) { int i, j, key; for (j = 1; j < LEN; j++) { printf("%d, %d, %d, %d, %d\n", a[0], a[1], a[2], a[3], a[4]); key = a[j]; i = j - 1; while (i >= 0 && a[i] > key) { a[i+1] = a[i]; i--; } a[i+1] = key; } printf("%d, %d, %d, %d, %d\n", a[0], a[1], a[2], a[3], a[4]); } int main(void) { insertion_sort(); return 0; }