Pagini recente » Cod sursa (job #2773627) | Cod sursa (job #262516) | Cod sursa (job #2381513) | Cod sursa (job #1499294)
#include <iostream>
#include <fstream>
#define nmax 500009
using namespace std;
int n,a[nmax];
ifstream fin("algsort.in");
ofstream fout("algsort.out");
void sortare(int st,int dr)
{
int i=st,j=dr,x=a[(i+j)/2];
do
{while(a[j]>x)j--;
while(a[i]<x)i++;
if(i<=j)
{swap(a[i],a[j]);
i++;j--;}
}while(i<=j);
if(j>st)sortare(st,j);
if(i<dr)sortare(i,dr);
}
int main()
{int i;
fin>>n;
for(i=1;i<=n;i++)
fin>>a[i];
sortare(1,n);
for(i=1;i<=n;i++)
fout<<a[i]<<' ';
}