Cod sursa(job #1880304)
| Utilizator | Data | 15 februarie 2017 17:47:10 | |
|---|---|---|---|
| Problema | Sortare prin comparare | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("algsort.in");
ofstream g("algsort.out");
int n,i,x[500010];
void quick_sort(int,int);
int main()
{
f>>n;
for(i=1;i<=n;i++)
f>>x[i];
quick_sort(1,n);
for(i=1;i<=n;i++)
g<<x[i]<<' ';
return 0;
}
void quick_sort(int L,int R)
{
int M=(L+R)/2,S=L,D=R;
if(L>=R)
return;
M=x[(L+R)/2];
do
{
while(x[S]<M)S++;
while(x[D]>M)D--;
if(S<=D){swap(x[S],x[D]);S++;D--;}
}
while(S<=D);
quick_sort(L,D);
quick_sort(S,R);
}
