Advertisement
Guest User

pilha.c

a guest
May 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include "pilha.h"
  2. #include <stdlib.h>
  3.  
  4. Pilha *create() {
  5. Pilha *p = (Pilha *) malloc(sizeof(Pilha));
  6. p->topo = -1;
  7. for (int i = 0; i < MAX; i++) {
  8. p->elementos[i] = 0;
  9. }
  10. return p;
  11. }
  12.  
  13. int isFull(Pilha *p) {
  14. return p->topo == MAX - 1;
  15. }
  16.  
  17. char pop(Pilha *p) {
  18. char c = p->elementos[p->topo];
  19. p->topo--;
  20. return c;
  21. }
  22.  
  23. int push(Pilha *p, char c) {
  24. if (isFull(p)) {
  25. return 0;
  26. }
  27. p->topo++;
  28. p->elementos[p->topo] = c;
  29. return 1;
  30. }
  31.  
  32. int isEmpty(Pilha *p) {
  33. return p->topo == -1;
  34. }
  35.  
  36. int size(Pilha *p) {
  37. return p->topo + 1;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement