(排序演算法)linux c語言實現快速排序
阿新 • • 發佈:2018-12-19
/*************************************************** ##filename : arrinsert.c ##author : GYZ ##e-mail : [email protected] ##create time : 2018-10-31 09:54:39 ##last modified : 2018-10-31 17:04:29 ##description : NA ***************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> void arrInsert(int a[],int n) { int temp = 0; int i = 0,j = 0; for(i = 1; i < n; ++i) { temp = a[i]; /* just a flag*/ for(j = i-1; j >= 0; --j) /*compare from (i-1 to 0) with the flag*/ { if(temp < a[j]) { a[j+1] = a[j]; a[j] = temp; } else { break; } } } } void printArr(int a[],int n) { int i; for(i = 0; i < n; i++) { printf("%d,",a[i]); } printf("\n"); } int main(int argc,char *argv[]) { int length = 0; int begin,end; int a[] = {21,22,23,24,25,26,27,28,29,30,11,12,13,14,15,16,17,18,19,20,10,3,5,6,1,9,4,8,2,7}; length = sizeof(a) / sizeof(a[0]); begin = clock(); arrInsert(a,length); end = clock(); printf("%d\n",end-begin); printArr(a,length); return 0; }