#include #include #include "collections.h" class Node { friend class DirStack; public: Node( Dir i, Node *n ); private: Dir item; Node *next; }; Node::Node( Dir i, Node *n ) : item( i ) , next( n ) {} DirStack::DirStack() : tos( NULL ) {} bool DirStack::isEmpty() { return !tos; } void DirStack::push( Dir dir ) { tos = new Node( dir, tos ); } Dir DirStack::pop() { assert( !isEmpty() ); Node *t = tos; tos = tos->next; Dir res = t->item; // delete t; return res; } Dir DirStack::top() { assert( !isEmpty() ); return tos->item; } void DirStack::print( ostream& os ) { for( Node *cur = tos; cur; cur = cur->next ) { os << cur->item << " "; } os << endl; }