/* PROGRAMA: pila_memoria_dinamica.cpp DESCRIPCIÓN: Implementando una piloa con memoria dinámica AUTOR: FJHL ACTUALIZACIÓN: 28/ENE/2016 */ #include #include typedef struct _nodo{ int valor; struct _nodo *siguiente; }tipoNodo; void push(tipoNodo **tope, int x); int pop(tipoNodo **tope); int main(void){ tipoNodo *tope = NULL; push(&tope, 10); push(&tope, 20); push(&tope, 30); printf("%d ", pop(&tope)); printf("%d ", pop(&tope)); printf("%d ", pop(&tope)); printf("%d ", pop(&tope)); printf("\n"); system("pause"); return(0); } void push(tipoNodo **tope, int x){ tipoNodo *nodo_nuevo; nodo_nuevo = (tipoNodo *)malloc(sizeof(tipoNodo)); nodo_nuevo->valor = x; nodo_nuevo->siguiente = *tope; *tope = nodo_nuevo; } int pop(tipoNodo **tope){ tipoNodo *nodo_aux; int x_aux; nodo_aux = *tope; if (nodo_aux == NULL){ printf("\nLa Pila está vacía..."); return(-1); } *tope = nodo_aux->siguiente; x_aux = nodo_aux->valor; //Liberar memoria free(nodo_aux); return (x_aux); }