Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "test.h"
- t_pilha* aloca_pilha(){
- t_pilha* ptr = (t_pilha *) malloc(sizeof(t_pilha));
- ptr->topo = NULL;
- return ptr;
- }
- void push(t_pilha* pilha, int valor){
- t_ele* ptr = (t_ele *) malloc(sizeof(t_ele));
- ptr->dado = valor;
- pilha->dado->prox = topo;
- pilha->topo = ptr->dado;
- }
- int pop(t_pilha* pilha){
- if(pilha_vazia(pilha)){
- printf("A pilha esta vazia\n");
- return;
- }
- int valor;
- pilha* aux = pilha->topo;
- pilha->topo = aux->prox;
- valor = pilha->dado;
- free(aux);
- return valor;
- }
- void get_topo(t_pilha* pilha){
- if(pilha_vazia(pilha)){
- printf("PILHA VAZIA\n");
- return;
- }
- printf("O primeiro elemento da pilha eh: %d\n", pilha->topo);
- }
- int pilha_vazia(t_pilha* pilha){
- return(pilha->topo == NULL);
- }
- int tam_pilha(t_pilha* pilha){
- int counter = 0;
- t_ele* atual = pilha->topo;
- while(atual != NULL){
- atual = atual->prox;
- counter++;
- }
- return counter;
- }
- void print_pilha(t_pilha* pilha){
- pilha* aux = pilha->topo;
- while(aux != NULL){
- printf("%d <- ", pilha->topo);
- pilha->topo = pilha->dado;
- aux = aux->prox;
- }
- printf(" NULL\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement