Advertisement
Guest User

bolje ovo

a guest
Oct 22nd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. void Obrisi_stablo(Cvor* koren, Cvor** stek, int *top)
  2. {
  3.     Cvor* pom;
  4.  
  5.     stek_push(stek, koren, top);
  6.  
  7.     while(top != 0)
  8.     {
  9.         koren = stek_pop(stek, top);
  10.         pom = koren;
  11.         free(koren);
  12.  
  13.         if(pom->desno != NULL)
  14.            stek_push(stek, koren->desno, top);
  15.  
  16.          if(pom->levo)
  17.            stek_push(stek, koren->levo, top);
  18.  
  19.     }
  20.  
  21.     printf("Stablo je obrisano!\n");
  22. }
  23.  
  24. Cvor* stek_pop(Cvor** stack, int * top)
  25. {
  26.     return stack[(*top)--];
  27. }
  28.  
  29. void stek_push(Cvor** stack, Cvor* cvor, int* top)
  30. {
  31.     if((*top) == -1)
  32.     {
  33.         stack[++(*top)] = cvor;
  34.     }
  35.     else
  36.       stack[(*top)++] = cvor;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement