// A stack class is defined here with a private internal storage // and public functions that can manipulate it. // include this file in any program that needs a stack of characters // This stack is based on ../c/stack.[ch] and uses a linked list. // Upgraded to 1997 style C++ in Feb 1998 #include #include struct top_t{ char d; top_t *next; }; struct stack{ private: top_t * tp; public: void make_new() { tp=0; } char top() { if(tp)return (tp -> d);else cerr<<"\ntop: empty stack"; exit(1); } bool empty() { return !tp; } void push(char c) { top_t * temp; temp = new top_t; temp->d = c; temp->next = tp; tp = temp; } char pop() { top_t * t1 = tp; char x; if(! empty() ){ x = t1->d; tp = t1->next; delete t1; return x; } else cerr<<"\npop: empty stack\n"; } bool full() { return false; }//Note: For compatability stack(){make_new();} //auto initialization ~stack(){while(!empty())pop();} // automatic destruction };