//File intstack.cpp #include #include /*exit*/ #include "intstack.h" #include "pmglobs.h" stack::stack() { top=NULL; } stack::~stack() { while (!empty()) pop(); top=NULL; } void stack::display() { node* p = top; while (p) { cout << p->info << " "; p = p->next; } cout << endl; } bool stack::empty() const { if (top==NULL) return true; else return false; } void stack::push(int item) { node* p=new node; p->info=item; p->next=top; top=p; } int stack::pop() { node* p; int n; if (empty()) { cout<<"\n\nSTACK UNDERFLOW!\n\n"; exit(1); } else { p=top; top=p->next; n=p->info; delete p; } return n; } int stack::stacktop() const { if (empty()) { cout<<"\n\nSTACK IS EMPTY!\n\n"; exit(1); } return top->info; } //B-16