//-----stack.cpp--------- //--------------------------------------------------------------------------- #include #pragma hdrstop //--------------------------------------------------------------------------- #pragma package(smart_init) #include "Stack.h" #include StringStack::StringStack() { head = 0; } StringStack::~StringStack() { StringNode* temp; while(head!=0) { temp=head; head = head->next; delete temp; } } void StringStack::push(string push_string) { StringNode* newNode = new StringNode(0, push_string); if(head==0) head = newNode; else { StringNode* ptr=head; while(ptr->next!=0) ptr=ptr->next; ptr->next = newNode; } } string StringStack::pop() { if(head==0) { cerr << "Stack Underflow."; return "0"; } StringNode* tempPtr = head->next; temp_string = head->data; delete head; head = tempPtr; return temp_string; } //-----Stack.h ---------- #include //--------------------------------------------------------------------------- #ifndef StackH #define StackH //--------------------------------------------------------------------------- #include "StringNode.h" class StringStack { public: StringStack(); ~StringStack(); void push(string); string pop(); private: StringNode* head; }; #endif