/////////////////////////////////////////////////////////////////// // graph.cpp - Solution of MT#1-Q1 // // // // This is a demo showing how to make the required declarations // // It provides no useful functionality. Main does nothing other // // Than create a node and a graph object. // /////////////////////////////////////////////////////////////////// #include #include /* node class is a container of a T */ template class node { public: T& value(); private: T t; }; /* Hook class for application specific processing. We could use this as template policy, but passing to traversal member allows us to apply many different derived operations configured at run-time. */ class operation { public: virtual ~operation(); virtual void doOp() = 0; }; /* Note that no copy, destruction, or assignment operations need be defined. Compiler generated will work correctly. */ template class graph { public: typedef T value_type; typedef node vertex; graph(); graph(const graph& g); void insert(const vertex& v); bool connect(vertex& v1, vertex& v2); void dfs(operation& op); private: typedef std::list< vertex > vertexList; typedef std::map< vertex, vertexList > adjacencyList; adjacencyList al; }; template graph::graph() {} template graph::graph(const graph& g) : al(g.al) {}; int main() { node n; graph g; }