摘要:
问题:希尔排序又叫缩小增量排序。增量的选取为d=length/2;d=d/2...d=1;代码:#include <iostream>using namespace std;void shellSort(int arr[],int length){ int d; int temp; int j,k; static int count=1; for(d=length/2;d>=1;d=d/2) { for(j=d;j<length;j++) { for(k=j-d;k>=0;k=k-d) { if(arr[k]>arr[k+d]) { temp=... 阅读全文
摘要:
问题:找临界点挺难的,是了好几次,终于OK了。代码:#include <iostream>using namespace std;void qSort(int arr[],int left,int right){ int i,j; int pos; static int count=1; if(left>=right) return; i=left; j=right; int key=arr[i]; pos=i; while(i<j) { while(i<j&&arr[j]>=key) { j--; } if(i<j&& 阅读全文
摘要:
代码:#include <iostream>using namespace std;typedef struct ss{ int i; int key;}iSort;void display(iSort arr[],int n){ for(int i=0;i<n;i++) { cout<<arr[i].key<<" "; } cout<<endl;}int main(){ iSort arr[10]; int temp; int k,j; int m; for(int i=0;i<10;i++) { cin> 阅读全文