Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <conio.h>
- #include <windows.h>
- using namespace std;
- const int tamanho = 100;
- struct _pilha {
- int index;
- int mem[tamanho];
- };
- void push(struct _pilha p,int valor)
- {
- if(p.index==tamanho-1)return;
- printf("ADICIONANDO %d\n",valor);
- p.index++;
- p.mem[p.index]=valor;
- printf("ADICIONANDO %d\n",p.index);
- system("PAUSE");
- }
- int pop(struct _pilha p)
- {
- if(p.index==-1)return -1;
- p.index--;
- return p.mem[p.index+1];
- }
- int queue(struct _pilha p)
- {
- return p.mem[p.index];
- }
- void mostrar(struct _pilha p)
- {
- system("CLS");
- for(int x=0;x<p.index;x++)
- printf("%3d: %4d\n",x,p.mem[x]);
- system("PAUSE");
- }
- int menu()
- {
- system("CLS");
- printf("Escolha uma opção:\n1: Adicionar valor a pilha\n2: Remover valor da pilha\n3: Mostrar pilha\n4: Sair");
- int x=getch();
- switch(x){
- case '1': return 1;
- case '2': return 2;
- case '3': return 3;
- case '4': ExitProcess(1);
- }
- }
- int main()
- {
- struct _pilha p;
- p.index=-1;
- int buffer;
- for(;;){
- switch(menu())
- {
- case 1:system("CLS"); printf("Digite um valor: "); scanf("%d",&buffer); push(p,buffer); break;
- case 2:pop(p); break;
- case 3:mostrar(p); break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement