///////////////////////////////////////////////////////////////// // theseus.h #ifndef MY_THESEUS #define MY_THESEUS #include "SWindows.h" #include "Graphics.h" #include "Delay.h" #include "Mouse.h" #include "IOTools.h" #include "MathUtil.h" #include "Random.h" #include "labyrinth.h" // Stack of Point to keep the thread, implemented as a singly linked list. // Instead of Point we could take any struct that contains a pair of ints. struct PointNode { Point data; PointNode * next; PointNode( Point d, PointNode * n ) : data(d), next(n) {} }; class PointStack { PointNode * first; public: PointStack() : first(NULL) {} // initially empty void Push( Point p ){ PointNode * ptr = new PointNode( p, first ); first = ptr; } void Pop(){ if( first == NULL ) return; // nothing to pop // else there is at least one node PointNode * ptr = first; first = first->next; delete ptr; // remove the popped node } Point Top(){ // return the top Point on the stack if( first == NULL ){ cerr << "PointStack underflow\n"; exit(-1); } // else the node on top is valid return first->data; } bool isEmpty(){ return first == NULL; } ~PointStack(){ // we need to deallocate all nodes one by one PointNode * ptr = first; PointNode * doomed; while( ptr != NULL ){ doomed = ptr; ptr = ptr->next; delete doomed; } } }; ///////////////////////////////////////////////////////////////// class Theseus { int x; // current coords int y; public: Theseus( ) : x(0), y(0) {} void Solve( Labyrinth & lbr, int x_ = 0 , int y_ = 0 ); // solve starting at position // ( x_, y_ ) }; #endif // MY_THESEUS