Pagini recente » Cod sursa (job #2440783) | Cod sursa (job #900550) | Cod sursa (job #966350) | Cod sursa (job #2003701) | Cod sursa (job #3208635)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <climits>
#include <cstring>
#define LL long long
#define billion 1000000000
const LL mod = 666013;
const double pi = 3.14159265359;
#define maxn 505
using namespace std;
ifstream fin("algsort.in");
ofstream fout("algsort.out");
int n;
vector<int> arr;
int Partition(int low, int high) {
int pivot = low;
int newPivotPos = high;
for (int i = low; i <= newPivotPos;) {
if (arr[i] > arr[pivot]) {
swap(arr[i], arr[newPivotPos]);
newPivotPos--;
}
else
i++;
}
swap(arr[pivot], arr[newPivotPos]);
return newPivotPos;
}
void QuickSort(int low, int high) {
if (low >= high)
return;
int newPivotPos = Partition(low, high);
QuickSort(low, newPivotPos-1);
QuickSort(newPivotPos+1, high);
}
void read() {
fin >> n;
int x;
for (int i = 1; i <= n; i++) {
fin >> x;
arr.push_back(x);
}
}
void print() {
for (int i = 0; i < n; i++)
fout << arr[i] << " ";
}
int main()
{
read();
QuickSort(0, n-1);
print();
return 0;
}