4eyes4u

Untitled

Jan 16th, 2017
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct cvor
  5. {
  6.     int val;
  7.     struct cvor *l, *r;
  8. }BCVOR;
  9.  
  10.  
  11. BCVOR *napraviStablo (int n, bool ok)
  12. {
  13.     if (!ok) return NULL;
  14.     else
  15.     {
  16.         BCVOR *v=(BCVOR *)malloc(sizeof(BCVOR));
  17.         v->val=n;
  18.         int x=n%10;
  19.         if (x!=n) v->l=napraviStablo(x, true); //ovo provearavam da ne bi slucajno imala broj 0 i ponovo dodala 0
  20.         else v->l=napraviStablo(x, false);
  21.  
  22.         int aux=n, y=0;
  23.         while (aux>10)
  24.         {
  25.             y=(y*10+aux%10);
  26.             aux/=10;
  27.         }
  28.         if (x!=n) v->r=napraviStablo(y, true); //isto i ovde
  29.         else v->l=napraviStablo(y, false);
  30.     }
  31. }
  32.  
  33. int main()
  34. {
  35.  
  36.  
  37.     BCVOR *root=(BCVOR *)malloc(sizeof (BCVOR));
  38.     root=NULL;
  39.  
  40.     int n;
  41.     scanf ("%d", &n);
  42.     root=napraviStablo(n, true);
  43.  
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment