/* * Stack implementation methods. */ #include "intstack.h" // Remove from the stack. int IntStack::pop() { if (head != NULL) { // Unlink the top node. StackNode *oldtop = head; head = head->next; // Get the data out of it, and destroy it. int retval = oldtop->data; delete oldtop; // Return the top value. return retval; } else return 0; } // Remove all memory from the stack. void IntStack::clear() { while(head != NULL) { // Advance the pointer and delete the old node. StackNode *zombie = head; head = head->next; delete head; } head = NULL; }