#include#include #include #include #include "runCLock.h"#define DEBUG_INSERT 1#define DEBUG_BUBBLE 1#define DEBUG_QUICK 1#define DEBUG_SELECT 1#define DEBUG_HEAP 1#define DEBUG_MERGE 1#define DEBUG_SHELL 1using namespace std;// data definationconst int LEN=60000;const int BOUNDARY=14997;//basic OPvoid init(int s[], const int LEN){ srand((unsigned)time(NULL)); for(int i=0; i =1 && tmp =1) { h=h/3; for(k=0; k=h && temp s[j+1]) { tmp=s[j]; s[j]=s[j+1]; s[j+1]=tmp; } } }}//quickSortint partition(int s[], int high, int low){ int pivot; pivot=s[low]; while(low=s[low]) { low++; } s[high]=s[low]; } s[low]=pivot; return low;}void qSort(int s[], int high, int low){ int pivotLoc; if(high>low) //except for only 1 element { pivotLoc=partition(s,high,low); qSort(s,high,pivotLoc+1); qSort(s,pivotLoc-1,low); }}void quickSort(int s[], int LEN){ qSort(s,LEN-1,0);}//selectSort()void selectSort(int s[], const int LEN){ int tmp; for(int i=0; i s[node]) { largeIndex=lc; } else { largeIndex=node; } if(rc<=len && s[rc]>s[largeIndex]) { largeIndex=rc; } if(largeIndex!=node) { tmp=s[largeIndex]; s[largeIndex]=s[node]; s[node]=tmp; heapAdjust(s,largeIndex,len); }}void heapSort(int s[], int len) //1...len{ int index=(len)/2; int tmp; //build heap for(int i=index; i>=1; i--) { heapAdjust(s,i,len); } //sort for(int i=len; i>1; i--) { tmp=s[i]; s[i]=s[1]; s[1]=tmp; heapAdjust(s,1,i-1); }}//merge Sortvoid merge(int s[], int low, int mid, int high) //low...mid mid+1...high{ int left[mid-low+1], right[high-mid]; int ss,ls,le,rs,re; ss=low; ls=0; le=mid-low; rs=0; re=high-mid-1; for(int i=low; i<=mid; i++) { left[i-low]=s[i]; } for(int i=mid+1; i<=high; i++) { right[i-mid-1]=s[i]; } while(ls<=le && rs<=re) { if(left[ls] low) { int mid=(high+low)/2; mSort(s,low,mid); mSort(s,mid+1,high); merge(s,low,mid,high); }}void mergeSort(int s[], int LEN){ mSort(s,0,LEN-1);}void shellSortChai(int *a,const int length){ int i,j,k,h; int temp; h=1; while(h 0){ h=h/3; for(i=0;i 0&&a[j]
#ifndef RUNCLOCK_H_INCLUDED#define RUNCLOCK_H_INCLUDED#includeclass runClock{ public: runClock(); void start(); void end(); double result(); void clear(); private: clock_t startTime, endTime;};#endif // RUNCLOCK_H_INCLUDED
#include "runClock.h"runClock::runClock(){ startTime=0.0; endTime=0.0;}void runClock::start(){ startTime=clock();}void runClock::end(){ endTime=clock();}double runClock::result(){ return double(endTime-startTime)/CLOCKS_PER_SEC;}void runClock::clear(){ startTime=0.0; endTime=0.0;}
运行结果: