Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct cvor
- {
- int broj;
- struct cvor *levi,*desni;
- } CVOR;
- void dodaj(CVOR *novi,cvor **koren);
- void pisi(CVOR *tekuci);
- main()
- {
- CVOR *koren=NULL,*novi=NULL;
- int br;
- printf("unesi brojeve a za kraj 0\n");
- do
- {printf("broj->");
- scanf("%d",&br);
- if(br!=0)
- {
- novi=(CVOR*)malloc(sizeof(CVOR));
- novi->broj=br;
- dodaj(novi,&koren);
- }
- }while(br!=0);
- printf("sadrzaj drveta je\n");
- pisi(koren);
- }
- void dodaj(CVOR*novi,CVOR **koren)
- {
- if(*koren==NULL)
- {*koren=novi;
- novi->levi=NULL;
- novi->desni=NULL;
- }else
- {if (novi->broj<(*koren)->broj)
- dodaj(novi,&(*koren)->levi);
- else
- dodaj(novi,&(*koren)->desni);
- }
- }
- void pisi(CVOR *tekuci)
- {
- if(tekuci!=NULL)
- {pisi(tekuci->levi);
- printf("->%d",tekuci->broj);
- pisi(tekuci->desni);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement