Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. typedef struct nod {
  6.     int nr;
  7.     nod *st, *dr;
  8. } * arbore;
  9. arbore r, t, g;
  10. int k=0, sum=0, nivel=0, niv=0, n=0;
  11. int max2,max1,min1,tem;
  12. int egale_cu_max;
  13. void creare(arbore &r){
  14.     int x;
  15.     cin>>x;
  16.     if(k==0)max1=x,min1=x,k=1;
  17.     if(x==0)r=NULL;
  18.     else{
  19.         if(max1<x)max1=x;if(min1>x)min1=x;
  20.         r=new nod;r->nr=x;
  21.         cout<<"Fiul stang al lui "<<x<<':';
  22.         creare(r->st);
  23.         cout<<"Fiul drept al lui "<<x<<':';
  24.         creare(r->dr);
  25.     }
  26. }
  27.  
  28.  
  29. void inordine(arbore r){
  30.     if(r!=NULL){
  31.         inordine(r->st);
  32.         cout<<r->nr<<' ';
  33.         inordine(r->dr);
  34.         if(r->st==NULL&&r->dr==NULL)
  35.         {
  36.             tem++;
  37.         }
  38.     }
  39. }
  40.  
  41. void afisare(arbore r,int nivel){
  42.     if(r!=NULL){
  43.         if (r->nr > max2) {
  44.             max2 = r->nr;
  45.             egale_cu_max = 1;
  46.         } else if (r->nr == max2)
  47.             egale_cu_max++;
  48.  
  49.         afisare(r->st,nivel+1);
  50.         for(int i=1;i<=nivel;i++)cout<<'\t';
  51.         cout<<r->nr<<endl;
  52.         afisare(r->dr,nivel +1);
  53.     }
  54. }
  55.  
  56.  
  57. int main()
  58. {
  59.         cout<<"Radacina:";
  60.     creare(r);
  61.     arbore u = r;
  62.     cout<<endl<<"Avem arborele:"<<endl;
  63.     afisare(r,0);
  64.  
  65.  
  66.     cout << "Parcurgerea in inordine:" << endl;
  67.     inordine(r);
  68.     cout << endl;
  69.    
  70.     cout<<"Max="<<max1<<endl;
  71.     cout<<"Min="<<min1<<endl;
  72.  
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement