|
@@ -1,10 +1,10 @@
|
|
|
|
|
|
#include <string>
|
|
|
+#include <map>
|
|
|
#include <set>
|
|
|
-using namespace std;
|
|
|
-
|
|
|
-
|
|
|
+#include <fstream>
|
|
|
|
|
|
+using namespace std;
|
|
|
class Node {
|
|
|
|
|
|
typedef set<Node*>::const_iterator node_iterator;
|
|
@@ -16,6 +16,7 @@ private:
|
|
|
void remove_neighboor(Node* neighboor);
|
|
|
|
|
|
public:
|
|
|
+ Node();
|
|
|
Node(const string& aname);
|
|
|
const string get_name() const;
|
|
|
|
|
@@ -27,20 +28,26 @@ public:
|
|
|
return neighboors.end();
|
|
|
};
|
|
|
|
|
|
+ const bool& operator == (const Node& r);
|
|
|
+
|
|
|
|
|
|
friend class Graph;
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
};
|
|
|
|
|
|
+
|
|
|
class Graph
|
|
|
{
|
|
|
-
|
|
|
typedef set<Node*>::const_iterator node_iterator;
|
|
|
-
|
|
|
private:
|
|
|
+ map <string, bool> taken_names;
|
|
|
set<Node*> nodes;
|
|
|
+
|
|
|
public:
|
|
|
Graph() {};
|
|
|
void add_node(Node* node);
|
|
@@ -48,6 +55,7 @@ public:
|
|
|
void add_edge(Node* begin, Node* end);
|
|
|
void remove_edge(Node* begin, Node* end);
|
|
|
|
|
|
+ void read_file(string file_name);
|
|
|
|
|
|
|
|
|
node_iterator begin() {
|
|
@@ -57,5 +65,34 @@ public:
|
|
|
node_iterator end() {
|
|
|
return nodes.end();
|
|
|
};
|
|
|
+ friend class Node;
|
|
|
};
|
|
|
|
|
|
+class Graph_exception {};
|
|
|
+
|
|
|
+
|
|
|
+class BFS
|
|
|
+{
|
|
|
+ typedef set<Node*>::const_iterator node_iterator;
|
|
|
+ const Graph& graph;
|
|
|
+public:
|
|
|
+ BFS(const Graph& agraph) : graph(agraph) {}
|
|
|
+ bool connected(Node* begin, Node* end);
|
|
|
+ friend Graph;
|
|
|
+ friend Node;
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+class DFS {
|
|
|
+ typedef set<Node*>::const_iterator node_iterator;
|
|
|
+private:
|
|
|
+ const Graph& graph;
|
|
|
+ set<Node*> visited;
|
|
|
+ bool connected(Node* begin, Node* end, int depth);
|
|
|
+public:
|
|
|
+
|
|
|
+ DFS(const Graph& agraph) : graph(agraph) {}
|
|
|
+ bool connected(Node* begin, Node* end);
|
|
|
+ friend Graph;
|
|
|
+ friend Node;
|
|
|
+};
|