Last active
August 29, 2015 14:20
-
-
Save rogerioagjr/68bb3ed87e4813ea8c81 to your computer and use it in GitHub Desktop.
Pilha
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define MAXT 1000100 // defino o limite de tamanho como 1000100 | |
int pilha[MAXT], tam; // declaro o vetor pilha e a variável tam | |
// função top: retirar o elemento do topo | |
void pop(){ if(tam>0) tam--; } // se tam>0, basta reduzí-la em 1 unidade | |
// função push: insere um elemento no topo | |
void push(int x){ pilha[++tam]=x; } // basta aumentar tam e inserir x na posição tam | |
// função clear: tira todos os elementos da pilha | |
void clear(){ tam=0; } // basta zerarmos a variável tam | |
// função top: retrna o lemento do topo | |
int top{ return pilha[tam]; } // bast retornar o elemento na posição tam |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment