// quick.cpp #include "stdafx.h" #include #include #include using namespace std; const int N = 1000000; int a [N]; void swap(int &c, int &k){ int pom; pom=c; c=k; k=pom; } void quick (int r, int s){ int i=r; int j=s; int h = a[(r+s)/2]; // cout << "quick (" << r << "," << s << ") :" << h << ":" << endl; // for (int k=r; k<=s; k++) cout << a[k] << ", "; // cout << endl; while (i <= j) { while (a[i]h) j--; // cout << "swap " << i << "," << j << ":" << a[i] << ":" << a[j] << endl; if (i < j) { swap (a[i],a[j]); } if (i <= j) { i++; j--; } // for (int k=r; k<=s; k++) cout << a[k] << ", "; // cout << endl; } // cout << "end swap " << r << "," << j << "," << i << "," << s << endl; // cout << endl << "........" << endl << endl; if (r < j) quick (r, j); if (i < s) quick (i, s); } void quicksort(int n) { assert (n <= N && n > 0); quick(0, n - 1); }; void vypis(int n) { for (int i=0; i