Cod sursa(job #1818750)

Utilizator DoubleNyNinicu Cristian DoubleNy Data 29 noiembrie 2016 19:42:01
Problema Sortare prin comparare Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli; 
typedef pair < int, int> dbl; 
const int maxInt = 1e9*2;
const lli maxLong = 1e18*2;
vector <int> vct; 

void qsort(int left, int right){
	
	int pivot = vct[(left + right) / 2];
	int i = left, j = right;
	
	while(i <= j){
			while(vct[i] < pivot)
				i++;
			while(vct[j] > pivot)
				j--;
			if(i <= j){
				swap(vct[i], vct[j]);
				i++;
				j--;
			}
	};
	if(left < j)
		qsort(left, j);
	if(i < right)
		qsort(i, right);
}

int main(){
	ifstream cin("algsort.in");
	ofstream cout("algsort.out");
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
			int a;
			cin >> a;
			vct.push_back(a);
	}
	/* SELECTION
		for(int i = 0; i < n; i++)
			for(int j = i + 1; j < n; j++)
				if(vct[i] > vct[j])
					swap(vct[i], vct[j]);
	*/
	/*
		sort(vct.begin(), vct.end());
	*/
	qsort(0, n - 1);
	for(int i = 0; i < n; i++)
			cout << vct[i] << ' ';
	return(0);
}