Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream fin("arbore.in");
- ofstream fout("arbore.out");
- int r, n, st[51], dr[51];
- void citire();
- {
- fin >> n >> r;
- for(int i = 1; i <= n; i++)
- fin >> st[i];
- for(i = 1; i <= n; i++)
- fin >> dr[i];
- }
- void preordine(int nod) {
- if(nod != 0) {
- fout << nod << ' ';
- preordine(st[nod]);
- preordine(dr[nod]);
- }
- }
- void inordine(int nod) {
- if(nod != 0) {
- inordine(st[nod]);
- fout << nod << ' ';
- inordine(dr[nod]);
- }
- }
- void postordine(int nod) {
- if(nod != 0) {
- postordine(st[nod]);
- postordine(dr[nod]);
- fout << nod << ' ';
- }
- }
- int main() {
- citire();
- fout << "preordine:";
- preordine(r);
- fout << "\n inordine:";
- inordine(r);
- fout << "\n postordine:";
- postordine(r);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement