Guest User

Untitled

a guest
Jul 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 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, *dr;
  12. }*rad;
  13.  
  14. char bla[30];
  15.  
  16. void creare ()
  17. {
  18. int n, i;
  19. in>>n;
  20. nod *p, *q;
  21. bool gasit=0;
  22. p=new nod;
  23. rad=p;
  24. rad->st = NULL;
  25. rad->dr = NULL;
  26. in>>rad->nume;
  27. in>>rad->medie;
  28. for (i=1; i<n; i++)
  29. {
  30. p=new nod;
  31. in>>p->nume>>p->medie;
  32. p->st=NULL;
  33. p->dr=NULL;
  34. q=rad;
  35. gasit=false;
  36. while (!gasit)
  37. {
  38. if (strcmp(q->nume,p->nume)>0)
  39. if (q->st==NULL)
  40. {
  41. q->st=p;
  42. gasit=true;
  43. }
  44. else
  45. q=q->st;
  46. else
  47. if (q->dr==NULL)
  48. {
  49. q->dr=p;
  50. gasit=true;
  51. }
  52. else
  53. q=q->dr;
  54. }
  55. }
  56. }
  57.  
  58. void inordine (nod *cnt)
  59. {
  60. if (cnt!=NULL)
  61. {
  62. inordine(cnt->st);
  63. if(strcmp(cnt->nume, bla)==0)
  64. cout<<cnt->medie;
  65. inordine(cnt->dr);
  66. }
  67.  
  68. }
  69.  
  70.  
  71.  
  72. int main ()
  73. {
  74. cin>>bla;
  75. creare ();
  76. inordine(rad);
  77.  
  78. return 0;
  79. }
Add Comment
Please, Sign In to add comment