/**
*2018.10.01 22:22
*直接插入排序
*/
#include<stdio.h>
#define MAX 100
void directInsertSort(int array[], int n);
int main(void) {
int array[] = {0,2,6,9,5,2,1,5,7,9,2,4};
directInsertSort(array, sizeof(array) / sizeof(int));
for (int i = 0; i < sizeof(array) / sizeof(int); ++i) {
printf("%d ", array[i]);
}
putchar('\n');
system("pause");
return 0;
}
void directInsertSort(int array[], int n) {
int i, j ,temp;
for (i = 1; i < n; ++i) {
temp = array[i];
j = i - 1;
while(j >= 0 && array[j] > temp){
array[j + 1] = array[j];
--j;
}
array[j + 1] = temp;
}
}
直接插入排序
最新推荐文章于 2024-03-19 18:50:33 发布