Pagini recente » Cod sursa (job #1598099) | Cod sursa (job #3243630) | Cod sursa (job #3196838) | Cod sursa (job #2960132) | Cod sursa (job #1716818)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int N;
vector<int> v;
void Read();
void Write();
void qSort(int left, int right);
void qSwap(int &a, int &b) {
if(a == b)
return;
a += b;
b = a - b;
a -= b;
}
int main()
{
Read();
qSort(1, N);
Write();
return 0;
}
void qSort(int left, int right) {
if(left >= right)
return;
int piv = (left + right) / 2;
int i = left, j = right;
while(i <= j) {
while(v[i] < v[piv])
i++;
while(v[j] > v[piv])
j--;
if(i <= j) {
qSwap(v[i], v[j]);
i++;
j--;
}
}
qSort(left, j);
qSort(i, right);
}
void Write() {
for(int i = 1; i <= N; ++i)
cout << v[i] << ' ';
cout << '\n';
}
void Read() {
freopen("algsort.in", "rt", stdin);
freopen("algsort.out", "wt", stdout);
scanf("%d", &N);
v.assign(N+2, 0);
for(int i = 1; i <= N; ++i)
scanf("%d", &v[i]);
}