Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<string.h>
- using namespace std;
- ifstream in("date.in");
- struct nod
- {
- char nume[30];
- float medie;
- nod *st;
- nod *dr;
- }*rad;
- char elev[30];
- void creare()
- {
- int n,i;
- in>>n;
- nod *p= new nod;
- rad=p;
- rad->st=NULL;
- rad->dr=NULL;
- in>>rad->nume;
- in>>rad->medie;
- bool gasit=0;
- nod *q;
- for(i=1;i<n;i++)
- {
- gasit=false;
- p=new nod;
- in>>p->nume>>p->medie;
- p->st=NULL;
- p->dr=NULL;
- q=rad;
- while(!gasit)
- {
- if(strcmp(q->nume,p->nume)>0)
- if(q->st==NULL)
- {
- q->st=p;
- gasit=true;
- }
- else
- q=q->st;
- else
- if(q->dr==NULL)
- {
- q->dr=p;
- gasit=true;
- }
- else
- q=q->dr;
- }
- }
- }
- void innord(nod *rad)
- {
- if(rad!=NULL)
- {
- innord(rad->st);
- cout<<rad->nume<<" "<<rad->medie<<endl;
- innord(rad->dr);
- }
- }
- bool da=false;
- void functie(nod *a)
- {
- if(a!=NULL)
- {
- functie(a->st);
- if(strcmp(a->nume,elev)==0)
- {
- cout<<"Media elevului "<<elev<<" este "<<a->medie<<" ";
- da=true;
- }
- functie(a->dr);
- }
- }
- int main()
- {
- cin>>elev;
- creare();
- cout<<endl<<endl<<endl;
- innord(rad);
- cout<<endl;
- functie(rad);
- if(da==false)
- cout<<"Dai drumul ca nu e in lista!";
- return 0;
- }
Add Comment
Please, Sign In to add comment