Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct cvor
- {
- int val;
- struct cvor *l, *r;
- }BCVOR;
- BCVOR *napraviStablo (int n, bool ok)
- {
- if (!ok) return NULL;
- else
- {
- BCVOR *v=(BCVOR *)malloc(sizeof(BCVOR));
- v->val=n;
- int x=(n-n%10)/10;
- if (x!=n) v->l=napraviStablo(x, true); //ovo provearavam da ne bi slucajno imala broj 0 i ponovo dodala 0
- else v->l=napraviStablo(x, false);
- int aux=n, y=0;
- while (aux>10)
- {
- y=(y*10+aux%10);
- aux/=10;
- }
- if (x!=n) v->r=napraviStablo(y, true); //isto i ovde
- else v->l=napraviStablo(y, false);
- }
- }
- int main()
- {
- BCVOR *root=(BCVOR *)malloc(sizeof (BCVOR));
- root=NULL;
- int n;
- scanf ("%d", &n);
- root=napraviStablo(n, true);
- return 0;
- }
Add Comment
Please, Sign In to add comment