12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #include "pileInt.h"
-
- #include <stdlib.h>
- #include <stdio.h>
-
- void initPileI( struct PileInt* p ) {
- p->height = 0;
- p->l = NULL;
- }
-
- void pushPileI( struct PileInt* p, programPointer i ) {
- struct ListInt* aux = p->l;
-
- p->l = (struct ListInt*)malloc(sizeof(struct ListInt));
- if (p->l == NULL) {
- fprintf(stderr, "Error: Could not allocate memory for the next cell on the stack");
- return;
- }
-
- p->l->next = aux;
- p->l->i = i;
- ++(p->height);
- }
-
- int topPileI( struct PileInt* p ) {
- if ( p->height == 0 ) {
- fprintf(stderr, "Error: The stack has no element, cannot find top");
- exit(1);
- }
- return p->l->i;
- }
-
- void popPileI( struct PileInt* p ) {
- struct ListInt* aux;
-
- if ( p->height != 0 ) {
- --(p->height);
- aux = p->l;
- p->l = p->l->next;
- free(aux);
- }
- }
-
- void endPileI( struct PileInt* p ) {
- while (p->height != 0) {
- popPileI(p);
- }
- }
|