#include #include void dump(char* str,int n, float a[]); void sort(int l, int r, float a[]); void straightInsertion(int n, float a[20]) { // // Leaves the order of items with equal keys unchanged. // int i,j; float x; for (i=2;i<=n;i++) { dump(" Insertion steps:",n, a); x=a[i]; a[0]=x; j=i-1; while(x=i;j--) { if(a[j-1]>a[j]) { // swap x=a[j-1]; a[j-1]=a[j]; a[j]=x; } } // j } // i } // *****************************************************8 void dump(char * str, int n, float a[20]) { int i; cout << str << " "; for(i=0;i<=n;i++) { cout << a[i] << " "; } cout << endl; } // ***************************************************** void quicksort(int n, float a[20]) { sort(1,n,a); } void sort(int l, int r, float a[20]) { // makes partitioning. int i,j; float x,w; i=l; j=r; x=a[(l+r)/2]; do { while(a[i]=l;j--) { a[j+1]=a[j]; } // for j // a[l]=x; } // for i } // ****************************************************** void shakesort(int n, float a[20]) { int j,k,l,r; float x; l=2; r=n; k=n; do { for(j=r;j>=l;j--) { if(a[j-1]>a[j]) { x=a[j-1]; a[j-1]=a[j]; a[j]=x; k=j; } } l=k+1; // // for(j=l;j<=r;j++) { if(a[j-1]>a[j]) { x=a[j-1]; a[j-1]=a[j]; a[j]=x; k=j; } } r=k-1; } while(l<=r); } // ====================================================