Cod sursa(job #262605)

Utilizator hello_thereLunmod Rotamargorp hello_there Data 19 februarie 2009 15:02:09
Problema Sortare prin comparare Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
/*
This code was written in a shit
... Bordland
*/
#include <stdio.h>

#define IN "sort.in"
#define OUT "sort.out"
#define N_MAX 1<<10

int N;
int V[N_MAX];

void scan()
{
	freopen(IN,"r",stdin);
	freopen(OUT,"w",stdout);

	scanf("%d",&N);
	int i;
	for(i=1;i<=N;++i)
		scanf("%d",&V[i]);

}

inline void swap(int &a,int &b)
{
    int aux = a;
    a = b;
    b = aux;
}

void sort(int l,int r)
{
	if(l>=r)
                return;

	int i=l,j = r;
	int mij = V[ (i+j)>>1 ];

	do
	{
		for(;V[i] < mij;++i);
		for(;V[j] > mij;--j);

		if(i<=j)
			swap(V[i++],V[j--]);


	}
	while(i<=j);

	sort(l,i-1);
	sort(i,r);

}

void solve()
{
	sort(1,N);

	int i;
	for(i=1;i<=N;++i)
		printf("%d ",V[i]);
}

int main()
{
	scan();
	solve();
	return 0;
}