#include <cstdio> #include <cstdlib> #include <stack> #include <algorithm> using namespace std; const int MAXN = 100000; int val[MAXN]; int n; void QSort(int l, int r) { if (l <= r) { int pivot = val[l + rand() % (r - l + 1)]; int low = l, high = r; while (low <= high) { while (val[low] < pivot) low++; while (val[high] > pivot) high--; if (low <= high) { swap(val[low], val[high]); low++; high--; } } QSort(l, high); QSort(low, r); } } void QuickSort() { QSort(0, n - 1); } int main() { scanf("%d", &n); for (int i = 0;i < n;i++) { scanf("%d", &val[i]); } QuickSort(); for (int i = 0;i < n;i++) { printf("%d ", val[i]); } puts(""); return 0; } /************************************************************** Problem: 2174 User: admin Language: C++ Result: Accepted Time:42 ms Memory:1540 kb ****************************************************************/