Advertisement
4eyes4u

Untitled

Jan 16th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 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. void umetni (BCVOR **root, BCVOR *x)
  11. {
  12.     if (*root==NULL)
  13.     {
  14.         *root=x;
  15.         x->l=NULL;
  16.         x->r=NULL;
  17.     }
  18.     else if (x->val < (*root)->val) umetni(&(*root)->l, x);
  19.     else umetni(&(*root)->r, x);
  20. }
  21.  
  22. int main()
  23. {
  24.     BCVOR *root=(BCVOR *)malloc(sizeof (BCVOR));
  25.     root=NULL;
  26.  
  27.     int x;
  28.     while (scanf ("%d", &x))
  29.     {
  30.         BCVOR *novi=(BCVOR *)malloc(sizeof (BCVOR));
  31.         novi->val=x;
  32.         umetni (&root, novi);
  33.     }
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement