Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <algorithm>
- using namespace std;
- ifstream fin("bimax.in");
- ofstream fout("bimax.out");
- int nt[5001],X,Y;
- struct nod
- {
- int info;
- nod * st, *dr;
- };
- void citire(nod * & p)
- {
- int x;
- fin>>x;
- if(x==0)
- p=NULL;
- else
- {
- p=new nod;
- p->info=x;
- citire(p->st);
- citire(p->dr);
- }
- }
- void preordine(nod * p)
- {
- if(p)
- {
- if(p->info>Y)
- Y=p->info;
- preordine(p->st);
- preordine(p->dr);
- }
- }
- void stergeTot(nod * & p)
- {
- if(p!=NULL)
- {
- stergeTot(p->st);
- stergeTot(p->dr);
- delete p;
- p=NULL;
- }
- }
- int main()
- {
- nod * p = NULL;
- citire(p);
- preordine(p->st);
- X=Y;
- Y=0;
- preordine(p->dr);
- fout<<X<<' '<<Y;
- stergeTot(p);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement