Escolar Documentos
Profissional Documentos
Cultura Documentos
h>
#include <stdlib.h>
void empilhar(int);
int desempilhar();
void listar();
void sair();
int main(){
int option;
int num;
while(1){
printf("1- Empilhar \n2- Desempilhar \n3- Listar \n4- Sair \nDigite a opcao
desejada: ");
scanf("%d", &option);
system("cls");
switch (option)
{
case 1:
printf("Digite o numero que voce deseja empilhar: ");
scanf("%d", &num);
empilhar(num);
break;
case 2:
printf("O numero %d foi desempilhado.", desempilhar());
break;
case 3:
listar();
break;
case 4:
sair();
exit(0);
default:
printf("Opcao invalida!\n");
break;
}
system("pause");
system("cls");
}
}
if (novo == NULL){
exit(1);
}
novo->info = num;
if (topo == NULL){
novo->prox = NULL;
}
else {
novo->prox = topo;
}
topo = novo;
}
int desempilhar(){
int num;
Nodo* aux;
if (topo == NULL){
printf("A pilha esta vazia!\n");
system("pause");
return;
}
num = topo->info;
aux = topo;
topo = topo->prox;
free(aux);
system("pause");
return num;
}
void listar(){
Nodo* aux;
aux = topo;
system("pause");
}
void sair(){
Nodo* aux;
aux = topo;
if(topo == NULL){
return;
}