Skip to content

Instantly share code, notes, and snippets.

@lesimoes
Created December 26, 2018 11:55
Show Gist options
  • Save lesimoes/88d6b73f5444a9dd79a335972076090d to your computer and use it in GitHub Desktop.
Save lesimoes/88d6b73f5444a9dd79a335972076090d to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define TAM 10
struct pilha {
int topo;
char elemen[TAM];
}Pilha;
void inicia(struct pilha *P){
P->topo = -1;
};
char topo(struct pilha *P){
if(P->topo == -1) return 0;
return P->elemen[P->topo];
};
int empilhar(struct pilha *P, char valor){
if(P->topo == TAM - 1) return 0;
P->topo ++;
P->elemen[P->topo] = valor;
return 1;
};
char desempilhar(struct pilha *P){
if(P->topo == -1) return 0;
P->topo --;
return P->elemen[P->topo];
};
int main(){
inicia(&Pilha);
empilhar(&Pilha, 'A');
empilhar(&Pilha, 'B');
printf("Empilhando... %c",topo(&Pilha));
desempilhar(&Pilha);
printf("\nDesempilhando... %c",topo(&Pilha));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment