Pagini recente » Cod sursa (job #1669684) | Cod sursa (job #1432922) | Cod sursa (job #2193532) | Cod sursa (job #2406952) | Cod sursa (job #2025620)
#include <iostream>
#include <fstream>
#include <algorithm>
#define BUFF_SIZE 100001
using namespace std;
ifstream in("algsort.in");
ofstream out("algsort.out");
/**char buffer[BUFF_SIZE];
int pos = 0;
void Read(int& a) {
while (!isdigit(buffer[pos]))
if (++pos == BUFF_SIZE)
in.read(buffer, BUFF_SIZE), pos = 0;
a = 0;
while (isdigit(buffer[pos]))
{
a = a * 10 + buffer[pos] - '0';
if (++pos == BUFF_SIZE)
in.read(buffer, BUFF_SIZE), pos = 0;
}
}**/
void quicksort(int *v, int x, int y) {
if (x < y) {
int i = x, j = y, pivot = v[x + (y - x)/2];
while (i <= j) {
while (v[i] < pivot)
i++;
while (v[j] > pivot)
j--;
if (i <= j) {
swap(v[i], v[j]);
i++;
j--;
}
}
if (i < y)
quicksort(v, i, y);
if (j > x)
quicksort(v, x, j);
}
}
int main() {
int n, *p;
in >> n;
p = new int[n + 1];
for (int i = 1; i <= n; i++)
in >> p[i];
quicksort(p, 1, n);
for (int i = 1; i <= n; i++)
out << p[i] << " ";
delete[] p;
in.close();
out.close();
return 0;
}