Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
typedef struct pilha {
int size;
int itens[10];
} Pilha;
Pilha* criapilha() {
Pilha *pilha = (Pilha*) malloc(sizeof(Pilha));
pilha->size = 0;
return pilha;
}
void pop(Pilha *pilha){
if(pilha->size == 0){
puts("pilha vazia");
} else {
printf("item removido: %d\n\n", pilha->itens[--pilha->size]);
free(pilha->itens[--pilha->size]);
}
}
void Push(Pilha *pilha, int item){
if (pilha->size == 10 ){
puts("Pilha esta cheia..\n\n");
}else{
pilha->itens[pilha->size++] = item;
}
}
void peek(Pilha *pilha){
if(pilha->size == 0){
puts("pilha vazia");
}else{
printf("o topo da pilha e: %d\n\n", pilha->itens[(pilha->size)- 1]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.