Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef struct nod {
- int nr;
- nod *st, *dr;
- } * arbore;
- arbore r, t, g;
- int k=0, sum=0, nivel=0, niv=0, n=0;
- int max2,max1,min1,tem;
- int egale_cu_max;
- void creare(arbore &r){
- int x;
- cin>>x;
- if(k==0)max1=x,min1=x,k=1;
- if(x==0)r=NULL;
- else{
- if(max1<x)max1=x;if(min1>x)min1=x;
- r=new nod;r->nr=x;
- cout<<"Fiul stang al lui "<<x<<':';
- creare(r->st);
- cout<<"Fiul drept al lui "<<x<<':';
- creare(r->dr);
- }
- }
- void inordine(arbore r){
- if(r!=NULL){
- inordine(r->st);
- cout<<r->nr<<' ';
- inordine(r->dr);
- if(r->st==NULL&&r->dr==NULL)
- {
- tem++;
- }
- }
- }
- void afisare(arbore r,int nivel){
- if(r!=NULL){
- if (r->nr > max2) {
- max2 = r->nr;
- egale_cu_max = 1;
- } else if (r->nr == max2)
- egale_cu_max++;
- afisare(r->st,nivel+1);
- for(int i=1;i<=nivel;i++)cout<<'\t';
- cout<<r->nr<<endl;
- afisare(r->dr,nivel +1);
- }
- }
- int main()
- {
- cout<<"Radacina:";
- creare(r);
- arbore u = r;
- cout<<endl<<"Avem arborele:"<<endl;
- afisare(r,0);
- cout << "Parcurgerea in inordine:" << endl;
- inordine(r);
- cout << endl;
- cout<<"Max="<<max1<<endl;
- cout<<"Min="<<min1<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement