Cod sursa(job #1239343)

Utilizator radudorosRadu Doros radudoros Data 8 octombrie 2014 22:02:34
Problema Sortare prin comparare Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include <fstream>
using namespace std;

int a[500000];

int partition(int i , int s)
{
	int l = i - 1;
	for (int j = i; j <= s;j++)
	if (a[j] <= a[s])
	{
		l++;
		int aux = a[j];
		a[j] = a[l];
		a[l] = aux;
	}
	return l;
}

void quicksort(int i, int s)
{
	if (i < s)
	{
		int q=partition(i, s);
		if (i == 2);
		quicksort(i, q - 1);
		quicksort(q + 1, s);
		
	}
}


int main()
{
	ifstream fin("algsort.in");
	ofstream fout("algsort.out");
	int n;
	fin >> n;
	for (int i = 0; i < n; i++)
	{
		fin >> a[i];
	}
	quicksort(0, n-1);
	for (int i = 0; i < n; i++)
	{
		fout << a[i] << ' ';
	}
}