Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. //definir o tamanho da pilha(quantidade de dados)
  5. #define tamanho 8
  6.  
  7.  
  8. struct tipo_ra{
  9. int dados[tamanho];
  10. int ini;
  11. int topo;
  12. };
  13.  
  14. tipo_ra identifica;
  15.  
  16. void push(int elemento){
  17. if(identifica.topo == tamanho){
  18. printf("Fila cheia.\n");
  19. system("pause");
  20. }
  21. else
  22. {
  23. identifica.dados[identifica.topo] = elemento;
  24. identifica.topo++;
  25. }
  26. }
  27.  
  28. int pop(){
  29. int elemento;
  30. if(identifica.topo == identifica.ini){
  31. printf("Fila vazia.\n");
  32. system("pause");
  33. }
  34. else
  35. {
  36. identifica.topo--;
  37. elemento = identifica.dados[identifica.topo];
  38. return elemento;
  39. }
  40. }
  41.  
  42. int main(){
  43. identifica.topo = 0;
  44. identifica.ini = 0;
  45. int aux;
  46.  
  47. printf("\n Disciplina: Estrutura de Dados I\n Material de Avaliação Prática de Aprendizagem - MAPA\n Aluno: Jonathas Ferreira de Oliveira Aquino\n");
  48. system("pause");
  49.  
  50. //empilhando RA
  51. printf("\n Empilhando RA...\n\n");
  52. printf(" 1 7 2 7 2 7 1 5\n\n");
  53.  
  54. //empilha RA
  55. push(1);
  56. push(7);
  57. push(2);
  58. push(7);
  59. push(2);
  60. push(7);
  61. push(1);
  62. push(5);
  63. system("pause");
  64.  
  65. //desempilhando RA
  66. printf("\n Desempilhando RA... \n\n");
  67. printf(" %d ", pop());
  68. printf("%d ", pop());
  69. printf("%d ", pop());
  70. printf("%d ", pop());
  71. printf("%d ", pop());
  72. printf("%d ", pop());
  73. printf("%d ", pop());
  74. printf("%d ", pop());
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement