Guest User

BINARNO STABLO

a guest
Apr 27th, 2018
234
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct CVOR
  6. {
  7.     int key;
  8.     struct CVOR*cvor_levo;
  9.     struct CVOR*cvor_desno;
  10. };
  11.  
  12. void dodaj(struct CVOR *i, int h)
  13. {
  14.     i->key=h;
  15. };
  16.  
  17. struct CVOR *create()
  18. {
  19.     CVOR *i=(CVOR*)malloc(sizeof(struct CVOR));
  20.     i->cvor_levo=0;
  21.     i->cvor_desno=0;
  22.     return i;
  23. };
  24.  
  25. void PREORDER(struct CVOR *i)
  26. {
  27.     printf("%d",i->key);
  28.     if(i->cvor_levo!=0)
  29.         PREORDER(i->cvor_levo);
  30.     if(i->cvor_desno!=0)
  31.         PREORDER(i->cvor_desno);
  32. };
  33.  
  34. void INORDER(struct CVOR *i)
  35. {
  36.  
  37.     if(i->cvor_levo!=0)
  38.         INORDER(i->cvor_levo);
  39.      printf("%d",i->key);
  40.     if(i->cvor_desno!=0)
  41.         INORDER(i->cvor_desno);
  42. };
  43.  
  44. void POSTORDER(struct CVOR *i)
  45. {
  46.    if(i->cvor_levo!=0)
  47.         POSTORDER(i->cvor_levo);
  48.     if(i->cvor_desno!=0)
  49.         POSTORDER(i->cvor_desno);
  50.     printf("%d",i->key);
  51. };
  52.  
  53. void main(void)
  54. {
  55.     struct CVOR*koren;
  56.  
  57.     koren=create();
  58.     dodaj(koren,10);
  59.  
  60.     koren->cvor_levo=create();
  61.     dodaj(koren->cvor_levo,6);
  62.  
  63.     koren->cvor_levo->cvor_levo=create();
  64.     dodaj(koren->cvor_levo->cvor_levo,3);
  65.  
  66.     koren->cvor_desno=create();
  67.     dodaj(koren->cvor_desno,16);
  68.  
  69.     koren->cvor_desno->cvor_levo=create();
  70.     dodaj(koren->cvor_desno->cvor_levo,12);
  71.  
  72.     koren->cvor_desno->cvor_desno=create();
  73.     dodaj(koren->cvor_desno->cvor_desno,18);
  74.  
  75.     koren->cvor_desno->cvor_desno->cvor_levo=create();
  76.     dodaj(koren->cvor_desno->cvor_desno->cvor_levo,17);
  77.  
  78.     koren->cvor_desno->cvor_desno->cvor_desno=create();
  79.     dodaj(koren->cvor_desno->cvor_desno->cvor_desno,22);
  80.  
  81.     koren->cvor_desno->cvor_levo->cvor_desno=create();
  82.     dodaj(koren->cvor_desno->cvor_levo->cvor_desno,13);
  83.  
  84.     printf("%s\n","PREORDER:");
  85.     PREORDER(koren);
  86.     printf("\n\n");
  87.  
  88.     printf("%s\n","INORDER:");
  89.     INORDER(koren);
  90.     printf("\n\n");
  91.  
  92.     printf("%s\n","POSTORDER:");
  93.     POSTORDER(koren);
  94.     printf("\n\n");
  95.  
  96. }
RAW Paste Data