Pagini recente » Cod sursa (job #2217717) | Cod sursa (job #2801565) | Cod sursa (job #1622316) | Cod sursa (job #1651605) | Cod sursa (job #3252614)
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define MAX 500000
using namespace std;
ifstream fin("algsort.in");
ofstream fout("algsort.out");
int32_t n, i, j, x, a[MAX], random1;
void Sort(int32_t st, int32_t dr)
{
if(st < dr)
{
srand(time(NULL));
random1 = st+rand()%(dr-st);
swap(a[random1], a[dr]);
i = st; j = dr; x = 0;
while(i < j)
{
if(a[i] > a[j])
{
swap(a[i], a[j]);
x = 1-x;
}
i += x;
j -= 1-x;
}
Sort(st, i-1);
Sort(i+1, dr);
}
}
int main()
{
ios_base::sync_with_stdio(false);
fin.tie(nullptr);
fout.tie(nullptr);
fin >> n;
for(i=0; i < n; i++) fin >> a[i];
Sort(0, n-1);
for(i=0; i < n; i++) fout << a[i] << ' ';
}