1213
2013-12-13 15:03
78 查看
void dbubble(sqlist r)//双向冒泡,排序元素r[1]~r { int i=1,j,b=1; struct rec t; while(b) { b=0; for(j=n-i+1;j>=i+1;j--) if(r[j].key<r[j-1].key) { b=1; t=r[j]; r[j]=r[j-1]; r[j-1]=t; } for(j=i+1;j<=n-i;j++) if(r[j].key>r[j+1].key) { b=1; t=r[j]; r[j]=r[j+1]; r[j+1]=t; } i++; } } void dbubble(sqlist r) { int i=1,j,b=1; struct rec r; while(b) { for(j=n-i+1;j>=i+1;j--) if(r[j].key>) } } //排序结束条件为没有交换元素为止,奇偶转换排序 void sort(int a[],int n) { int i,flag; int temp; do{ flag=0; for(i=0;i<n;i++)//两次i++ { if(a[i]>a[i+1]) { flag=1; temp=a[i+1]; a[i+1]=a[i]; a[i]=temp; } i++; } for(i=1;i<n;i++) { if(a[i]>a[i+1]) { flag=1; temp=a[i+1]; a[i+1]=a[i]; a[i]=temp; } i++; } }while(flag!=0) } void quicksort(sqlist r,int t1,int t2)//实现快速排序的非递归算法 { int stack[m0][2],i,top=0; stack[top][0]=t1; stack[top][1]=t2; while(top>-1) { t1=stack[top][0]; t2=stack[top][1]; top--; partition(r,t1,t2,i); if(t1<i-1) { top++; stack[top][0]=t1; stack[top][1]=i-1; } if(i+1<t2) { top++; stack[top][0]=i+1; stack[top][1]=t2; } } } void partition(sqlist r,int l,int h,int i)//分区 { int i=1;j=h; struct rec x; x=r[i];//初始化,x为基准 do//从右向左扫描,查找第一个关键字小于x.key的记录 { while(x.key<=r[j].key&&j>i) j--; if(j>i) { r[i]=r[j];//相当于交换r[i]和r[j] i++; } while(x.key>=r[i].key&&i<j)//从右向左扫描,查找第一个关键字大于x.key的记录 i++; if(i<j)//找到r[i],key>x.key,相当于交换r[i]和r[j] { r[j]=r[i]; j--; } }while(i!=j)//基准x已最终定位 r[i]=x; } void quicksort(type a[],int left,int right) { type temp,pivot; int i,j; if(left<right) { pivot=median3(a,left,right); i=left,j=right-1; for(;;) { while(i<j&&a[i]<pivot) i++; while(i<j&&pivot<a[j]) j--; if(i<j) { temp=a[i]; a[i]=a[j]; a[j]=temp; i++; j--; } else break; } if(a[i]>pivot) { temp=a[i]; a[i]=a[right]; a[right]=temp; } quicksort(a,left,i-1); quicksort(a,i+1,right); } } typedef median3(typed a[],int left,int right) { int mid=(left+right)/2; type temp; if(a[left]>a[mid]) { temp=a[left]; a[left]=a[mid]; a[mid]=temp; } if(a[right]>a[mid]) { temp=a[right]; a[right]=a[mid]; a[mid]=temp; } if(a[right]<a[left]) { temp=a[right]; a[right]=a[left]; a[left]=temp; } return a[right]; } void quicksort(type a[],int left,int right) { type temp,pivot; int i,j; while(left<right) { pivot=median3(a,left,right); i=left; j=right-1; for(;;) { while(i<j&&a[i]<pivot) i++; while(i<j&&pivot<a[j]) j--; if(i<j) { temp=a[i]; a[i]=a[j]; a[j]=temp; i++; j--; } else break; } if(a[i]>pivot) { temp=a[i]; a[i]=a[right]; a[right]=temp; } quicksort(a,left,i-1); left=i+1; } } #define MAX 100 typedef struct stacknode { int left,right; }Stack; void quicksort(type a[],int left,int right) { Stack s[MAX]; int top-1; type temp,pivot; top++; s[top].left=left; s[top].right=right; while(top>-1) { left=s[top].left; right=s[top].right; top--; while(left<right) { pivot=median3(a,left,right); i=left; j=right-1; for(;;) { while(i<j&&a[i]<pivot) i++; while(i<j&&pivot<a[j]) j--; if(i<j) { temp=a[i]; a[i]=a[j]; a[j]=temp; i++; j--; } else break; } if(a[i]>pivot) { temp=a[i]; a[i]=a[right]; a[right]=temp; } top++; s[top].left=i+1; s[top].right=right; right=i-1; } } } void sort(int A[],int n) { int i,j,temp,minval,minidx; for(i=0;i<n-1;i++) { minval=A[i]; mindix=i; for(j=i+1;j<n;j++) if(A[j]<minval) { minval=A[j]; mindix=j; } if(mindix!=i) { temp=A[i]; A[i]=A[minidx]; A[minidx]=temp; } } }
相关文章推荐
- hdu 1213 How Many Tables
- 1213
- HDU 1213 How Many Tables(并查集)
- POJ-1213-Roman Numerals
- HDU 1213 How Many Tables
- HDU 1213 How Many Tables 并查集
- WIKIOI 1213 解的个数 题解与分析
- hdu——1213——How Many Tables
- HDU 1213 How Many Tables
- HDOJ 1213 How Many Tables——并查集
- HDOJ 1213 How Many Tables
- WIKIOI 1213 解的个数 题解与分析
- HDU - 1213 - How Many Tables <并查集>
- hdu 1213 How Many Tables
- HDU 1213 How Many Tables
- 【BZOJ】1213 高精度开根
- HDU 1213 How Many Tables
- hdoj 1213 How Many Tables【并查集】
- 1213:How Many Tables
- hdu 1213 How Many Tables(并查集)