Pagini recente » Cod sursa (job #2711868) | Cod sursa (job #836182) | Cod sursa (job #3294359) | Cod sursa (job #1878851) | Cod sursa (job #1977038)
#include <stdio.h>
#include <algorithm>
#define nmax 500010
using namespace std;
int n;
int t[nmax];
int particion(int st, int dr)
{
int pivot = t[dr];
int pIndex = st;
for (int i = st; i < dr; i++)
if (t[i] <= pivot) {
swap(t[i], t[pIndex]);
pIndex++;
}
swap(t[dr], t[pIndex]);
return pIndex;
}
void quicksort(int st, int dr)
{
if (st < dr) {
int pIndex = particion(st, dr);
quicksort(st, pIndex - 1);
quicksort(pIndex + 1, dr);
}
}
int main()
{
freopen("algsort.in", "r", stdin);
freopen("algsort.out", "w", stdout);
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &t[i]);
quicksort(1, 6);
for (int i = 1; i <= n; i++) printf("%d ", t[i]);
return 0;
}