Advertisement
webmanix

misterios da fe

Nov 6th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <windows.h>
  5.  
  6. using namespace std;
  7.  
  8. const int tamanho = 100;
  9.  
  10. struct _pilha {
  11. int index;
  12. int mem[tamanho];
  13. };
  14.  
  15. void push(struct _pilha p,int valor)
  16. {
  17. if(p.index==tamanho-1)return;
  18. printf("ADICIONANDO %d\n",valor);
  19. p.index++;
  20. p.mem[p.index]=valor;
  21. printf("ADICIONANDO %d\n",p.index);
  22. system("PAUSE");
  23. }
  24.  
  25. int pop(struct _pilha p)
  26. {
  27. if(p.index==-1)return -1;
  28. p.index--;
  29. return p.mem[p.index+1];
  30. }
  31.  
  32. int queue(struct _pilha p)
  33. {
  34. return p.mem[p.index];
  35. }
  36.  
  37. void mostrar(struct _pilha p)
  38. {
  39. system("CLS");
  40. for(int x=0;x<p.index;x++)
  41. printf("%3d: %4d\n",x,p.mem[x]);
  42. system("PAUSE");
  43. }
  44.  
  45.  
  46. int menu()
  47. {
  48. system("CLS");
  49. printf("Escolha uma opção:\n1: Adicionar valor a pilha\n2: Remover valor da pilha\n3: Mostrar pilha\n4: Sair");
  50. int x=getch();
  51. switch(x){
  52. case '1': return 1;
  53. case '2': return 2;
  54. case '3': return 3;
  55. case '4': ExitProcess(1);
  56. }
  57.  
  58. }
  59.  
  60. int main()
  61. {
  62. struct _pilha p;
  63. p.index=-1;
  64. int buffer;
  65. for(;;){
  66. switch(menu())
  67. {
  68. case 1:system("CLS"); printf("Digite um valor: "); scanf("%d",&buffer); push(p,buffer); break;
  69. case 2:pop(p); break;
  70. case 3:mostrar(p); break;
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement