Pagini recente » Cod sursa (job #1863459) | Cod sursa (job #1268057) | Cod sursa (job #49143) | Cod sursa (job #2900420) | Cod sursa (job #724308)
Cod sursa(job #724308)
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#define parent(nod) (nod)/2
#define left_child(nod) (nod)*2
#define right_child(nod) (nod)*2+1
using namespace std;
std::vector<std::string> v;
int n;
void citire();
template<typename T>
void swap(T &a,T &b)
{
T aux=a; a=b; b=aux;
}
void qsort(int l,int r)
{
int i=l,j=r,t=(l+r)/2;
while(i<=j)
{
while(v[i]<v[t]) ++i;
while(v[j]>v[t]) --j;
if(i<=j)
{
swap(v[i],v[j]);
++i;
--j;
}
}
if(i<r) qsort(i,r);
if(l<j) qsort(l,j);
}
int main()
{
citire();
qsort(1,n);
ofstream fout("algsort.out");
for(int i = 1; i<=n; ++i)
fout << v[i] <<' ';
fout.close();
return 0;
}
void citire()
{
std::string aux;
ifstream fin("algsort.in");
fin >> n;
getline(fin,aux);
getline(fin,aux);
std::istringstream sin(aux);
std::string _aux;
v.push_back("");
for(int i = 1; i <= n; ++i)
{
sin >> _aux;
v.push_back(_aux);
}
fin.close();
}