#include #include "node.h" #include "stack.h" using namespace std ; Stack::Stack() { top = NULL ; } Stack::~Stack() { node * current = this->top ; while(current != NULL) { node * tmp = current ; current = current->next ; delete tmp ; } } void Stack::Push(int x) { node * newnode = new node() ; newnode->data = x ; newnode->next = this->top ; this->top = newnode ; } int Stack::Pop() { int returnvalue = this->top->data ; node * tmp = this->top ; this->top = this->top->next ; delete tmp ; return returnvalue ; } bool Stack::IsEmpty() { return (this->top == NULL) ; } void Stack::Print() { node * current = this->top ; while(current != NULL) { cout << current->data << " " ; current = current->next ; } } Stack & Stack::operator=(Stack & other) { node * current = other.top ; while(current != NULL) { this->Push(current->data) ; current = current->next ; } return * this ; } bool Stack::operator==(const Stack & other) { node * current1 = this->top ; node * current2 = other.top ; while(current1 != NULL & current2 != NULL) { if(current1 == NULL and current2 != NULL) return false ; if(current1 != NULL and current2 == NULL) return false ; if(current1->data != current2->data) return false ; else { // they were the same } } return true ; } ostream & operator<<(ostream & out, const Stack & other) { node * current = other.top ; while(current != NULL) { out << current->data << " " ; current = current->next ; } return out ; }