GustavoAraujo

Estrutura Pilha

Mar 3rd, 2014
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #define max 5
  2.  
  3. typedef struct{
  4.       int tamanho;
  5.       int item[max];
  6. } pilha;
  7. void iniciar(pilha &pilha)
  8. {
  9.     pilha.item[0] = pilha.tamanho = -1;
  10. }
  11. void push(pilha &p, int n)
  12. {
  13.     ++p.item[++p.tamanho] = n;
  14. }
  15. void pop(pilha &p)
  16. {
  17.     if(p.tamanho != -1) p.item[p.tamanho--] = -1;
  18. }
  19. int top(pilha &p)
  20. {
  21.     return p.item[p.tamanho];
  22. }
  23. int size(pilha &p)
  24. {
  25.     return p.tamanho+1;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment