Pagini recente » Cod sursa (job #2442777) | Cod sursa (job #942369) | Cod sursa (job #3255917) | Cod sursa (job #2687916) | Cod sursa (job #3237753)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin ("algsort.in");
ofstream fout("algsort.out");
struct nod {
int inf;
nod *st;
nod *dr;
};
nod *r;
int n, i, x;
void insereaza(nod *&r, int x) {
if (r == NULL) {
r = new nod;
r->inf = x;
r->st = r->dr = NULL;
} else {
if (r->inf < x)
insereaza(r->dr, x);
else
insereaza(r->st, x);
}
}
void afiseaza(nod *r) {
if (r) {
afiseaza(r->st);
fout<<r->inf<<" ";
afiseaza(r->dr);
}
}
int main() {
ifstream fin ("algsort.in");
ofstream fout("algsort.out");
fin>>n;
vector<int> v;
for (i=1;i<=n;i++) {
fin>>x;
v.push_back(x);
}
random_shuffle(v.begin(), v.end());
for (i=1;i<=n;i++) {
fin>>x;
insereaza(r, x);
}
afiseaza(r);
return 0;
}