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, *dr;
- }*rad;
- char bla[30];
- void creare ()
- {
- int n, i;
- in>>n;
- nod *p, *q;
- bool gasit=0;
- p=new nod;
- rad=p;
- rad->st = NULL;
- rad->dr = NULL;
- in>>rad->nume;
- in>>rad->medie;
- for (i=1; i<n; i++)
- {
- p=new nod;
- in>>p->nume>>p->medie;
- p->st=NULL;
- p->dr=NULL;
- q=rad;
- gasit=false;
- 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 inordine (nod *cnt)
- {
- if (cnt!=NULL)
- {
- inordine(cnt->st);
- if(strcmp(cnt->nume, bla)==0)
- cout<<cnt->medie;
- inordine(cnt->dr);
- }
- }
- int main ()
- {
- cin>>bla;
- creare ();
- inordine(rad);
- return 0;
- }
Add Comment
Please, Sign In to add comment