#include #include #define PILA_TAMANO 10000 #define DESEMPILA_OK 999966 #define DESEMPILA_MAL 67 #define PILA_VACIA 1101 #define PILA_CON_DATOS 1102 struct unaPilaPosiciones { int tope; int xs[PILA_TAMANO]; int ys[PILA_TAMANO]; }; void iniPila(struct unaPilaPosiciones *p){ (*p).tope = 0; } void pushPila(struct unaPilaPosiciones *p, int x,int y){ (*p).xs[(*p).tope] = x; (*p).ys[(*p).tope] = y; (*p).tope++; } int popPila(struct unaPilaPosiciones *p, int *x,int *y){ if ((*p).tope ==0 ) { return DESEMPILA_MAL; } (*p).tope--; *x = (*p).xs[(*p).tope]; *y = (*p).ys[(*p).tope]; return DESEMPILA_OK; } int pilaVacia(struct unaPilaPosiciones *p){ if ((*p).tope == 0) { return PILA_VACIA; } return PILA_CON_DATOS; } int main(){ struct unaPilaPosiciones a; int x,y; iniPila(&a); for (int i=0; i<8; i++) { x = i; y = i+1; pushPila(&a, x,y); printf("\nInserto en la pila (%d , %d)",x,y); } printf("\n\n"); for (int i=0; i<13; i++) { if (popPila(&a, &x,&y) == DESEMPILA_OK) { printf("\nSaco de la pila (%d , %d)",x,y); } else { printf("\nError, intento sacar de la pila cuando ya no hay nada"); } } printf("\n\n"); for (int i=0; i<2; i++) { x = 100*i; y = 100*i+1; pushPila(&a, x,y); printf("\nInserto en la pila (%d , %d)",x,y); } printf("\n\n"); while (pilaVacia(&a) == PILA_CON_DATOS) { popPila(&a, &x,&y); printf("\nSaco de la pila (%d , %d)",x,y); } return 0; }