Pagini recente » Cod sursa (job #111834) | Cod sursa (job #2331113) | Cod sursa (job #1598137) | Cod sursa (job #1336634) | Cod sursa (job #797050)
Cod sursa(job #797050)
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
using namespace std;
typedef unsigned int uint32;
template <class Iter>
void quicksort(Iter start, Iter end)
{
if (std::distance(start, end) > 1)
{
Iter pivot = start + (end - start)/2;
Iter partIndex = partition(start, end, bind2nd(less_equal<uint32>(), *pivot));
quicksort(start, partIndex-1);
quicksort(partIndex+1, end);
}
}
int main()
{
int n;
vector<uint32> vec;
fstream fin("algsort.in", fstream::in);
fstream fout("algsort.out", fstream::out);
fin >> n;
//cout << n << endl;
vec.reserve(n);
istream_iterator<uint32> inIt(fin);
istream_iterator<uint32> eofIt;
copy(inIt, eofIt, back_inserter(vec));
/*for (int i=0; i<n; ++i)
{
fin >> vec[i];
cout << vec[i] << " ";
}
cout << endl;*/
quicksort(vec.begin(), vec.end());
ostream_iterator<uint32> outIt(fout, " ");
copy(vec.begin(), vec.end(), outIt);
//cout << endl;
return 0;
}