Pagini recente » Cod sursa (job #731327) | Cod sursa (job #744767) | Cod sursa (job #1842592) | Monitorul de evaluare | Cod sursa (job #346518)
Cod sursa(job #346518)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
namespace me{
template<class c> void sort(c a,c b);
}
int main(){
vector<int> v;
{ifstream in("algsort.in");
int n;in>>n;
for(;n>0;n--){
int t;in>>t;
v.push_back(t);
}
}
//the sorting part;
me::sort(v.begin(),v.end());
{ofstream out("algsort.out");
for(int i=0;i<v.size();i++){
out<<v[i]<<" ";
}
}
}
template<class c> void me::sort(c a,c b){
if(a==b) return;
if(a+1==b){if(*a>*b) swap(*a,*b);return;}
c m=a,n=b;bool flip=false;
while(m!=n){if(flip)m++;else n--;flip=!flip;}
me::sort(a,m);
me::sort(m,b);
for(;a<b;a++){
if(*a>*m){
for(c t=a;t<m;t++){
swap(*t,*m);
}
m++;
}
}
}