#include "stackP.h" #include StackT::StackT(){ top = nullptr; size = 0; return; } void StackT::Copy(const StackT & other) { NodeT * i,*j; size = other.size; top = nullptr; if (other.top != nullptr) { // build the first node top = new NodeT; top->data = other.top->data; top->next = nullptr; // build all other nodes i = top; j = other.top; while(j->next != nullptr) { j = j->next; i->next = new NodeT; i = i->next; i->next = nullptr; i->data = j->data; } } return; } StackT::StackT(const StackT & other) { Copy(other); return; } void StackT::Delete(){ NodeT * i,*j; i = top; top = nullptr; while (i != nullptr) { j = i; i=i->next; delete j; } return; } StackT::~StackT(void) { Delete(); return; } StackT & StackT::operator = (const StackT & other) { if (this != &other) { Delete(); Copy(other); } return *this; } // missing routines. void StackT::Push(ItemT i) { NodeT * tmp; size++; tmp = new NodeT; tmp->data = i; tmp->next = top; top = tmp; return; } ItemT StackT::Pop(void){ ItemT rv; NodeT * tmp; if (top != nullptr) { rv = top->data; tmp = top; top = top->next; delete tmp; size--; } return rv; } ItemT StackT::Top(void) const{ ItemT rv; if (top != nullptr) { rv = top->data; } return rv; } int StackT::Size(void) const{ return size; } bool StackT::IsEmpty(void) const{ return top==nullptr; }