Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define max 5
- typedef struct{
- int tamanho;
- int item[max];
- } pilha;
- void iniciar(pilha &pilha)
- {
- pilha.item[0] = pilha.tamanho = -1;
- }
- void push(pilha &p, int n)
- {
- ++p.item[++p.tamanho] = n;
- }
- void pop(pilha &p)
- {
- if(p.tamanho != -1) p.item[p.tamanho--] = -1;
- }
- int top(pilha &p)
- {
- return p.item[p.tamanho];
- }
- int size(pilha &p)
- {
- return p.tamanho+1;
- }
Advertisement
Add Comment
Please, Sign In to add comment