#include #include #include #define MAXSTACK 2048 using namespace std; template void BubbleSortVer1(T a[], long size) { long i,j; T x; for(i=0;ii;j--) { if (a[j-1]>a[j]) { x=a[j-1]; a[j-1]=a[j]; a[j]=x; } } } } template void BubbleSortVer2(T a[], long size) { long j, k = size-1; long lb=1, ub = size-1; T x; do { for(j=ub;j>0;j--) { if (a[j-1]>a[j]) { x=a[j-1]; a[j-1]=a[j]; a[j]=x; k=j; } } lb = k+1; for(j=1;j<=ub;j++) { if (a[j-1]>a[j]) { x=a[j-1]; a[j-1]=a[j]; a[j]=x; k=j; } } ub = k-1; } while (lb void ChoiceSort(T a[], long size) { long i,j,k; T x; for(i=0;i void InsertSortVer1(T a[], long size) { T x; long i, j; for (i=0;i=0&&a[j]>x;j--) a[j+1]=a[j]; a[j+1]=x; } } template void SetMin(T& val) { val=static_cast(std::numeric_limits::min()); } template void InsertSortVer2(T a[], long size) { T x; long i, j; T backup=a[0]; SetMin(a[0]); for (i=1;ix;j--) a[j+1]=a[j]; a[j+1]=x; } for (j=1;j0?--s:0; } template void ShellSort(T a[], long size) { long inc, i, j, seq[40]; int s; s=increment(seq, size); while (s>=0) { inc=seq[s--]; for (i=inc;i= 0)&&(a[j]>temp);j -= inc) a[j+inc]=a[j]; a[j+inc]=temp; } } } template void downPyramid(T a[], long k, long n) { T new_elem; long child; new_elem=a[k]; while(k <= n/2) { child=2*k; if( child=a[child]) break; a[k]=a[child]; k=child; } a[k]=new_elem; } template void PyramidSort(T a[], long size) { long i; T temp; for(i=size/2-1;i>=0;i--) downPyramid(a,i,size-1); for(i=size-1;i>0;i--) { temp=a[i]; a[i]=a[0]; a[0]=temp; downPyramid(a,0,i-1); } } template void QuickSortVer1(T* a, long N) { long i=0, j=N; T temp, p; p=a[N>>1]; do { while (a[i]p) j--; if (i<=j) { temp=a[i]; a[i]=a[j]; a[j]=temp; i++; j--; } } while (i<=j); if (j>0) QuickSortVer1(a,j); if ( N>i) QuickSortVer1(a+i,N-i); } template void QuickSortVer2(T a[], long size) { long i, j; long lb, ub; long lbstack[MAXSTACK], ubstack[MAXSTACK]; long stackpos = 1; long ppos; T pivot; T temp; lbstack[1]=0; ubstack[1]=size-1; do { lb=lbstack[stackpos]; ub=ubstack[stackpos]; stackpos--; do { ppos=(lb+ub)>>1; i=lb; j=ub; pivot=a[ppos]; do { while (a[i]lb) { stackpos++; lbstack[stackpos]=lb; ubstack[stackpos]=j; } lb = i; } } while (lb void Work() { int ch,size; T a[size]; cout<<"Please, enter the size of massive to sort!"<>size; while (ch !=27) { Message(); ch = getch(); switch(ch) { case 49: { srand((unsigned int)time(0)); for(int i=0;i(a, size); time=GetTickCount()-time; for(int i=0; i(a, size); time=GetTickCount()-time; for(int i=0; i(a, size); time=GetTickCount()-time; for(int i=0; i(a, size); time=GetTickCount()-time; for(int i=0; i(a, size); time=GetTickCount()-time; for(int i=0; i(a, size); time=GetTickCount()-time; for(int i=0; i(a, size); time=GetTickCount()-time; for(int i=0; i(a, size); time=GetTickCount()-time; for(int i=0; i(a, size); time=GetTickCount()-time; for(int i=0; i> choice; switch(choice) { case 1: Work; break; case 2: Work; break; case 3: Work; break; case 4: Work; break; } } }