Gabriel_Rofl

test.c

Oct 9th, 2017
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "test.h"
  4.  
  5.  
  6. t_pilha* aloca_pilha(){
  7. t_pilha* ptr = (t_pilha *) malloc(sizeof(t_pilha));
  8. ptr->topo = NULL;
  9. return ptr;
  10. }
  11.  
  12. void push(t_pilha* pilha, int valor){
  13.  
  14. t_ele* ptr = (t_ele *) malloc(sizeof(t_ele));
  15. ptr->dado = valor;
  16. pilha->dado->prox = topo;
  17. pilha->topo = ptr->dado;
  18. }
  19.  
  20. int pop(t_pilha* pilha){
  21. if(pilha_vazia(pilha)){
  22. printf("A pilha esta vazia\n");
  23. return;
  24. }
  25. int valor;
  26. pilha* aux = pilha->topo;
  27. pilha->topo = aux->prox;
  28. valor = pilha->dado;
  29. free(aux);
  30. return valor;
  31. }
  32.  
  33.  
  34. void get_topo(t_pilha* pilha){
  35. if(pilha_vazia(pilha)){
  36. printf("PILHA VAZIA\n");
  37. return;
  38. }
  39. printf("O primeiro elemento da pilha eh: %d\n", pilha->topo);
  40. }
  41.  
  42. int pilha_vazia(t_pilha* pilha){
  43. return(pilha->topo == NULL);
  44. }
  45.  
  46. int tam_pilha(t_pilha* pilha){
  47. int counter = 0;
  48. t_ele* atual = pilha->topo;
  49. while(atual != NULL){
  50. atual = atual->prox;
  51. counter++;
  52. }
  53. return counter;
  54. }
  55.  
  56. void print_pilha(t_pilha* pilha){
  57.  
  58. pilha* aux = pilha->topo;
  59. while(aux != NULL){
  60. printf("%d <- ", pilha->topo);
  61. pilha->topo = pilha->dado;
  62. aux = aux->prox;
  63. }
  64. printf(" NULL\n");
  65. }
Add Comment
Please, Sign In to add comment