Stack Code
These have to do with the linked list version of stacks
This assumes that if there's no space, new sets its argument to nil
struct stkrec {
int thing;
stkrec *next;
};
stkrec *STK = NULL; /* stack pointer */
int pop()
{
// returns the object on the top of the stack and removes it
int object stkrec *y;
1. if (STK != NULL) {
2. x = STK->thing;
3. y = STK;
4. STK = STK->next;
5. delete y;
6. return(x);
7. }
8. return(-1);
} //pop
void
push(int stuff)
{
// puts stuff on top of stack
1. stkrec *x = new stkrec ;
2. if (x != NULL) {
3. x^.thing = stuff
4. x^.next = STK; // put it on the front of the list
5. STK = x;
6. }
} //push