Pagini recente » Borderou de evaluare (job #2400018) | Cod sursa (job #1255259) | Cod sursa (job #1247669) | Cod sursa (job #1013837) | Cod sursa (job #1018218)
#include <iostream>
#include <stdio.h>
#include <stdlib.h>;
using namespace std;
int a[500001];
int n;
void qsort(int left, int right){
if (left < right){
int pivot = a[(left+right)/2];
int i= left;
int j=right;
int sw;
while (i<=j){
while (a[i] < pivot){
i++;
}
while (a[j] > pivot){
j--;
}
if (i <= j){
sw = a[i];
a[i] = a[j];
a[j] = sw;
i++;
j--;
}
}
qsort(left, j);
qsort(i, right);
}
}
int main()
{
freopen("algsort.in", "r", stdin);
freopen("algsort.out", "w", stdout);
scanf("%d", &n);
for (int i=0; i<n; i++){
scanf("%d", &a[i]);
}
qsort(0, n-1);
for (int i=0; i<n; i++){
printf("%d ", a[i]);
}
return 0;
}