Guest User

Untitled

a guest
Jul 16th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string.h>
  4. using namespace std;
  5. ifstream in("date.in");
  6.  
  7. struct nod
  8. {
  9.     char nume[30];
  10.     float medie;
  11.     nod *st;
  12.     nod *dr;
  13. }*rad;
  14. char elev[30];
  15. void creare()
  16. {
  17.     int n,i;
  18.     in>>n;
  19.     nod *p= new nod;
  20.     rad=p;
  21.     rad->st=NULL;
  22.     rad->dr=NULL;
  23.     in>>rad->nume;
  24.     in>>rad->medie;
  25.     bool gasit=0;
  26.     nod *q;
  27.     for(i=1;i<n;i++)
  28.     {
  29.         gasit=false;
  30.         p=new nod;
  31.         in>>p->nume>>p->medie;
  32.         p->st=NULL;
  33.         p->dr=NULL;
  34.         q=rad;
  35.         while(!gasit)
  36.         {
  37.             if(strcmp(q->nume,p->nume)>0)
  38.                 if(q->st==NULL)
  39.                 {
  40.                     q->st=p;
  41.                     gasit=true;
  42.                 }
  43.                 else
  44.                     q=q->st;
  45.             else
  46.                 if(q->dr==NULL)
  47.                 {
  48.                     q->dr=p;
  49.                     gasit=true;
  50.                 }
  51.                 else
  52.                     q=q->dr;
  53.         }
  54.     }
  55. }
  56. void innord(nod *rad)
  57. {
  58.     if(rad!=NULL)
  59.     {
  60.         innord(rad->st);
  61.         cout<<rad->nume<<" "<<rad->medie<<endl;
  62.         innord(rad->dr);
  63.     }
  64. }
  65. bool da=false;
  66. void functie(nod *a)
  67. {
  68.     if(a!=NULL)
  69.     {
  70.         functie(a->st);
  71.         if(strcmp(a->nume,elev)==0)
  72.         {
  73.             cout<<"Media elevului "<<elev<<" este "<<a->medie<<" ";
  74.             da=true;
  75.         }
  76.         functie(a->dr);
  77.     }
  78. }
  79. int main()
  80. {
  81.     cin>>elev;
  82.     creare();
  83.     cout<<endl<<endl<<endl;
  84.     innord(rad);
  85.     cout<<endl;
  86.    
  87.     functie(rad);
  88.     if(da==false)
  89.         cout<<"Dai drumul ca nu e in lista!";
  90.     return 0;
  91. }
Add Comment
Please, Sign In to add comment