2、pe.h>#include#include#include#include#include#include#include#include//状态代码#defineTURE1#defineFALSE0#defineOK1#defineERROR0#defineINFEASIBLE-1typedefintStatus;..typedefintBoolean;c9.h#
3、defineEQ(a,b)((a)==(b))#defineLT(a,b)((a)<(b))#defineLQ(a,b)((a)<=(b))c10-1.h#defineMAXSIZE20typedefintKeyType;structRedType{KeyTypekey;InfoTypeotherinfo;};structSqList{RedTyper[MAXSIZE+1];intlength;};2、插入排序在同一文件夹中建立如下5个文件:c1.h,c9.h,c10-1.h,bo10-1.cpp,algo10-1
4、.cpp.对algo10-1.cpp进行编译、构建和运行。bo10-1.cppvoidInsertSort(SqList&L){inti,j;for(i=2;i<=L.length;++i)..ifLT(L.r[i].key,L.r[i-1].key){L.r[0]=L.r[i];for(j=i-1;LT(L.r[0].key,L.r[j].key);--j)L.r[j+1]=L.r[j];L.r[j+1]=L.r[0];}}voidBInsertSort(SqList&L){inti,j,m,low,high;f
5、or(i=2;i<=L.length;i++){L.r[0]=L.r[i];low=1;high=i-1;while(low<=high){m=(low+high)/2;ifLT(L.r[0].key,L.r[m].key)high=m-1;elselow=m+1;}for(j=i-1;j>=high+1;--j)L.r[j+1]=L.r[j];L.r[high+1]=L.r[0];}..}algo10-1.cpp#include"c1.h"typedefintInfoType;#include"c9.h"#inc
6、lude"c10-1.h"#include"bo10-1.cpp"voidprint(SqListL){inti;for(i=1;i<=L.length;i++)printf("(%d,%d)",L.r[i].key,L.r[i].otherinfo);printf("");}#defineN8voidmain(){RedTyped[N]={{49,1},{38,2},{65,3},{97,4},{76,5},{13,6},{27,7},{49,8}};SqListl1,l2;inti;for(i=0;i7、i++)l1.r[i+1]=d[i];l1.length=N;..l2=l1;printf("排序前:");print(l1);InsertSort(l1);printf("直接插入排序后:");print(l1);BInsertSort(l2);printf("折半插入排序后:");print(l2);}3、希尔排序在同一文件夹中建立如下4个文件:c1.h,c9.h,c10-1.h,algo10-3.cpp.对algo10-3.cpp进行编译、构建和运行。algo10-3.cpp//algo10-3.
8、cpp希尔排序#includetypedefintInfoType;#include"c9.h"#include"c10-1.h"voidShellInsert(SqList&L,intdk){inti,j;for(i=dk+1;i<=L.length;++i)ifLT(L.r[i].key,L.r[i-dk].key){..L.r[0]=