Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<stdlib.h>
- #include<malloc.h>
- typedef struct estrutura
- {
- int valor;
- estrutura *prox;
- }NO;
- typedef struct
- {
- NO* topo;
- }PILHA;
- void inicializar(PILHA *p)
- {
- p->tapo =-1;
- }
- void push(PILHA *p, int valor)
- {
- NO* novo = (NO*) malloc(sizeof(NO));
- novo->valor = valor;
- novo->prox = p->topo;
- p->topo = novo;
- }
- int pop(PILHA *p)
- {
- if(p->topo < 0) return -1;
- int resposta = p->topo->valor;
- NO* aux = p->topo;
- p->topo = p->topo->prox;
- free(aux);
- return resposta;
- }
- void imprimir(PILHA *p)
- {
- NO* c = p->topo;
- while(c)
- {
- printf("%1 ", c->valor);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment