今天进行了篮球考试,考了投篮和上篮,应该能及格,下午去上了数据结构写了
快速排序
int Partition(SqList L,int low,int high) { L.elem[0]=L.elem[low]; int pivotkey=L.elem[0]; while(low<high) { while(low<high&&L.elem[high]>=pivotkey)--high; L.elem[low]=L.elem[high]; while(low<high&&L.elem[low]<=pivotkey)++low; L.elem[high]=L.elem[low]; } L.elem[low]=L.elem[0]; return low; }
堆排序
void HeapAdjust(HeapType H,int s,int m) { int rc=H.elem[s]; for(int j=2*s;j<=m;j*=2) { if(j<m&&H.elem[j]<H.elem[j+1])++j; if(rc>=H.elem[j])break; H.elem[s]=H.elem[j];s=j; } H.elem[s]=rc; }
归并排序
void Merge(SqList L,int low,int m,int high) { int i,j,k; i=j=low; k=m+1; int arr[1001]; while(j<=m&&k<=high) { if(L.elem[j]<L.elem[k]) arr[i++]=L.elem[j++]; else arr[i++]=L.elem[k++]; } while(j<=m)arr[i++]=L.elem[j++]; while(k<=high)arr[i++]=L.elem[k++]; for(int l=low;l<=high;l++) { L.elem[l]=arr[l]; } }
直接插入排序
void InsertSort(SqList L) { int j; for(int i=2;i<=L.Length;++i) { if(L.elem[i]<L.elem[i-1]) { L.elem[0]=L.elem[i]; L.elem[i]=L.elem[i-1]; for( j=i-2;L.elem[0]<L.elem[j];--j) L.elem[j+1]=L.elem[j]; L.elem[j+1]=L.elem[0]; } } }
希尔排序
void ShellInsert(SqList L,int dk) { for(int i=dk+1;i<=L.Length;++i) { int j; if(L.elem[i]<L.elem[i-dk]) { L.elem[0]=L.elem[i]; for(j=i-dk;j>0&&L.elem[0]<L.elem[j];j-=dk) L.elem[j+dk]=L.elem[j]; L.elem[j+dk]=L.elem[0]; } } }
标签:12,21,int,void,elem,high,low,SqList From: https://www.cnblogs.com/xuechenhao173/p/17920317.html