Advertisement
tonibiro

ASD lab8 prob3

Dec 3rd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4.  
  5. struct nod
  6. {
  7.   char info[50];
  8.   nod *st, *dr;
  9. };
  10.  
  11. void add_nod(nod *&rad, char a[])
  12. {
  13.   if(rad == NULL)
  14.   {
  15.     nod *r = new nod;
  16.     strcpy(r->info, a);
  17.     r->st = r->dr = NULL;
  18.     rad = r;
  19.     return;
  20.   }
  21.   else
  22.   {
  23.     if(strcmp(a, rad->info) > 0)
  24.       add_nod(rad->st, a);
  25.     else
  26.       {if(strcmp(a, rad->info) < 0)
  27.         add_nod(rad->dr, a);
  28.       else
  29.         return;
  30.       }
  31.   }
  32. }
  33.  
  34. void inordine(nod *rad)
  35. {
  36.   if(rad)
  37.   {
  38.     inordine(rad->st);
  39.     printf("%s, ", rad->info);
  40.     inordine(rad->dr);
  41.   }
  42. }
  43.  
  44. void cit_cuvinte(nod *rad)
  45. {
  46.   char a[50];
  47.   int n, i = 0;
  48.   printf("n: " );
  49.   scanf("%d", &n);
  50.   while(i < n)
  51.   {
  52.     scanf("%s", a);
  53.    
  54.     add_nod(rad, a);
  55.     ++i;
  56.   }
  57.   inordine(rad);
  58. }
  59.  
  60. int main()
  61. {
  62.   nod *rad = NULL;
  63.   cit_cuvinte(rad);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement