Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct no {
- int valor;
- struct no *prox;
- };
- struct no *base=NULL;
- void push(int x){
- if(base == NULL){
- base = (struct no *) malloc(sizeof(struct no*));
- base->valor = x;
- return;
- }
- struct no *aux = base;
- while(aux->prox != NULL){
- aux = aux->prox;
- }
- struct no *novo = (struct no *) malloc(sizeof(struct no*));
- aux->prox = novo;
- novo->valor = x;
- printf("%d\n",base->valor);
- }
- void mostrar(){
- if(base == NULL) return;
- while(base != NULL){
- printf("%d\n", base->valor);
- base = base->prox;
- }
- }
- void pop(){
- if(base == NULL) return;
- if(base->prox == NULL){
- free(base);
- base = NULL;
- }
- struct no *aux = base;
- struct no *ant;
- while(aux->prox != NULL){
- ant = aux;
- aux = aux->prox;
- }
- free(aux);
- ant->prox = NULL;
- return;
- }
- int main(){
- push(8);
- push(9);
- push(10);
- //mostrar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement