希尔排序(Shell's Sort)的C语言实现
生活随笔
收集整理的這篇文章主要介紹了
希尔排序(Shell's Sort)的C语言实现
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原創文章,轉載請注明來自鋼鐵俠Mac博客http://www.cnblogs.com/gangtiexia
?
希爾排序(Shell's Sort)又稱“縮小增量排序”(Diminishing Increment Sort)的基本思想不斷縮小步長后分組排序,具體步驟為 演示實例: C語言實現(編譯器Dev-c++5.4.0,源代碼后綴.cpp) 1 #include <stdio.h> 2 #define LEN 9 3 4 typedef float keyType; 5 6 typedef struct{ 7 keyType score; 8 char name[20]; 9 }student; 10 11 typedef struct{ 12 int length=LEN; 13 student stu[LEN]; 14 }sqList; 15 16 void shellInsert(sqList &L,int step){ 17 for(int k=1;k<=step&&k<L.length;k++) 18 { 19 20 for(int i=k+step;i<L.length;i+=step){ 21 L.stu[0]=L.stu[i]; 22 int j; 23 for(j=i-step;L.stu[j].score<L.stu[0].score&&j>0&&(j+step)<L.length;j=j-step) 24 { 25 L.stu[j+step]=L.stu[j]; 26 } 27 L.stu[j+step]=L.stu[0]; 28 } 29 } 30 31 } 32 33 void shellSort(sqList &L){ 34 int delta[5]={7,6,5,3,1}; 35 for(int k=0;k<5;k++){ 36 shellInsert(L,delta[k]); 37 } 38 } 39 40 int main(){ 41 sqList L; 42 43 for(int i=1;i<L.length;i++){ 44 printf("\n請輸入第%d個學生的姓名:",i); 45 gets(L.stu[i].name); 46 printf("分數:"); 47 scanf("%f",&(L.stu[i].score)); 48 getchar(); 49 } 50 51 shellSort(L); 52 53 for(int i=1;i<L.length;i++){ 54 printf("\n學生%s 分數%f 第%d名",L.stu[i].name,L.stu[i].score,i); 55 } 56 return 1; 57 }?
轉載于:https://www.cnblogs.com/gangtiexia/p/5097195.html
總結
以上是生活随笔為你收集整理的希尔排序(Shell's Sort)的C语言实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mybatis 复习笔记02
- 下一篇: 1.UI初认识