//#include "Node.h"; #include "stack.h"; #include ; using namespace std; // create an empty stack Stack::Stack(): head(NULL),theSize(0){ } // copy constructor for a stack Stack::Stack(const Stack & orig) { *this = orig; } // destroy nodes in stack Stack:: ~Stack() { clear(); } Stack & Stack::operator= (const Stack & rhs) { cout << "starting =" << endl; if (this != &rhs) { clear(); head = NULL; Node * temp = rhs.head; if (temp != NULL) { head = new Node(temp->getValue()); Node * current = head; temp = temp->getNext(); while (temp != NULL) { current->setNext(new Node(temp->getValue())); current = current->getNext(); temp = temp->getNext(); } } theSize = rhs.size(); } return *this; } // push elt on the stack void Stack::push(string elt) { head = new Node(elt,head); theSize++; } // pop elt from the stack void Stack::pop() { Node *temp = head; head = head->getNext(); theSize--; delete temp; } // return top element from the stack string Stack::top() const { return head->getValue(); } bool Stack::isEmpty() const { return theSize == 0; } void Stack::clear() { while (head != NULL) { pop(); } } int Stack::size() const { return theSize; } void Stack::printString() const { Node *temp = head; cout << "Stack: " << endl; while (temp != NULL) { cout << temp->getValue() << endl; temp = temp->getNext(); } cout << "End of stack" << endl; }