Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define max 20
- struct stack{
- int vet[max];
- int top;
- }typedef node;
- void iniciar(node *p) {
- p->top=-1;
- }
- void push(node *p,int x){
- if (p->top==19) printf("%s","\nStack Overflow\n");
- else{
- p->top++;
- p->vet[p->top]=x;
- }
- }
- int pop(node *p){
- int x;
- if(p->top==-1)printf("%s","\nStack Underflow\n");
- x=p->vet[p->top];
- p->top--;
- return x;
- }
- void mostrar(node *p){
- int i;
- if(p->top==-1)printf("%s","\nStack Underflow\n");
- printf("\n");
- for(i=p->top;i>=0;i--) printf("[%d]\n",p->vet[i]);
- }
- void menor100(node *p){
- printf("%d\n",p->vet[p->top]);
- }
- int menu(){
- int opc;
- printf(" _________________________________\n");
- printf("|_______________Menu______________|\n");
- printf("| |\n");
- printf("|0-Sair |\n");
- printf("|1-Inserir |\n");
- printf("|2-Excluir. |\n");
- printf("|3-Mostrar. |\n");
- printf("|4-Topo |\n");
- printf("|_________________________________|\n");
- printf("Digite uma opcao: ");
- scanf("%d",&opc);
- return opc;
- }
- int main(){
- int x,opc;
- node pilha;
- iniciar(&pilha);
- do{
- opc=menu();
- switch(opc){
- case 0:
- break;
- case 1:
- printf("Digite um valor: ");
- scanf("%d",&x);
- push(&pilha,x);
- break;
- case 2:
- printf("Excluido: %d\n",pop(&pilha));
- break;
- case 3:
- mostrar(&pilha);
- break;
- case 4:
- menor100(&pilha);
- break;
- default:
- printf("Opcao invalida\n");
- break;
- }
- system("pause");
- system("cls");
- }while(opc!=2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment