-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgraph.cpp
109 lines (92 loc) · 2.35 KB
/
graph.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "graph.h"
using std::string;
Graph1 *create() {
//string graph_name = 'g'+std::to_string(counter++);
Graph1 *g1 = new Graph1;
return g1;
}
void destroy(Graph1 &graph) {
delete &graph;
}
Graph1 &addVertex(Graph1 &graph, const char* vertex) {
try
{
graph.addVertex(string(vertex));
}
catch(const std::exception& e)
{
std::cout << e.what() << '\n';
}
return graph;
}
Graph1 &addVertex(Graph1 &graph, string vertex) {
try{
graph.addVertex(vertex);
}
catch(const std::exception& e)
{
std::cout << e.what() << '\n';
}
return graph;
}
Graph1 &addEdge(Graph1 &graph, string vertex1, string vertex2) {
try{
if (!Vertex::checkVertexName(vertex1) || !Vertex::checkVertexName(vertex2)){
throw WrongVertexName();
}
if (!graph.isContain(vertex1) || !graph.isContain(vertex2)){
throw ArgumentNotFound();
}
std::pair<string, string> edge;
edge.first =vertex1;
edge.second = vertex2;
graph.addEdge(edge);
} catch(const std::exception& e)
{
std::cout << e.what() << '\n';
}
return graph;
}
Graph1& addEdge(Graph1& graph, const char* vertex1, const char* vertex2) {
try
{
if (!Vertex::checkVertexName(vertex1) || !Vertex::checkVertexName(vertex2)){
throw WrongVertexName();
}
if (!graph.isContain(vertex1) || !graph.isContain(vertex2)){
throw ArgumentNotFound();
}
std::pair<string, string> edge;
edge.first =vertex1;
edge.second = vertex2;
graph.addEdge(edge);
}
catch(const std::exception& e)
{
std::cout << e.what() << '\n';
}
return graph;
}
void disp(Graph1 &graph) {
std::cout << graph;
}
Graph1 &graphUnion(Graph1 &graph_in1, Graph1 &graph_in2, Graph1 &graph_out) {
graph_out = graph_in1 + graph_in2;
return graph_out;
}
Graph1 &graphIntersection(Graph1 &graph_in1, Graph1 &graph_in2, Graph1 &graph_out) {
graph_out = graph_in1 ^ graph_in2;
return graph_out;
}
Graph1 &graphDifference(Graph1 &graph_in1, Graph1 &graph_in2, Graph1 &graph_out) {
graph_out = graph_in1 - graph_in2;
return graph_out;
}
Graph1 &graphProduct(Graph1 &graph_in1, Graph1 &graph_in2, Graph1 &graph_out) {
graph_out = graph_in1*graph_in2;
return graph_out;
}
Graph1 &graphComplement(Graph1 &graph_in, Graph1 &graph_out) {
graph_out = !graph_in;
return graph_out;
}