4
4
#include < vector>
5
5
#include < stdexcept>
6
6
7
+
7
8
template <typename Data>
8
9
class Graph {
9
10
public:
@@ -44,12 +45,12 @@ class Graph {
44
45
return *this ;
45
46
}
46
47
clearEdges ();
47
-
48
+
48
49
vertices = other.vertices ;
49
50
edgeMatrix.resize (other.edgeMatrix .size ());
50
51
for (size_t i = 0 ; i < other.edgeMatrix .size (); ++i) {
51
52
if (other.edgeMatrix [i] != nullptr ) {
52
- edgeMatrix[i] = new Edge (*other.edgeMatrix [i]);
53
+ edgeMatrix[i] = new Edge (*other.edgeMatrix [i]);
53
54
}
54
55
else {
55
56
edgeMatrix[i] = nullptr ;
@@ -82,16 +83,16 @@ class Graph {
82
83
Edge*& exists_edge = edgeMatrix[startIv * qty_vertex + endIv];
83
84
84
85
if (exists_edge != nullptr ) {
85
- delete exists_edge;
86
+ delete exists_edge;
86
87
}
87
88
88
89
exists_edge = new Edge (edge_data);
89
90
90
91
if (type == GraphType::Undirected) {
91
92
Edge*& exists_ReverseEdge = edgeMatrix[endIv * qty_vertex + startIv];
92
-
93
+
93
94
if (exists_ReverseEdge != nullptr ) {
94
- delete exists_ReverseEdge;
95
+ delete exists_ReverseEdge;
95
96
}
96
97
97
98
exists_ReverseEdge = new Edge (edge_data);
@@ -100,16 +101,17 @@ class Graph {
100
101
101
102
102
103
104
+
103
105
void remove_Edge (size_t startIv, size_t endIv) {
104
- if (startIv >= get_VertexAmount () || endIv>= get_VertexAmount ()) {
106
+ if (startIv >= get_VertexAmount () || endIv >= get_VertexAmount ()) {
105
107
throw std::out_of_range (" Vertex index out of range." );
106
108
}
107
109
108
110
size_t index = startIv * get_VertexAmount () + endIv;
109
111
delete edgeMatrix[index ];
110
112
edgeMatrix[index ] = nullptr ;
111
113
112
-
114
+
113
115
if (type == GraphType::Undirected) {
114
116
size_t reverse_Index = endIv * get_VertexAmount () + startIv;
115
117
delete edgeMatrix[reverse_Index];
@@ -119,7 +121,7 @@ class Graph {
119
121
120
122
Edge* get_Edge (size_t startIv, size_t endIv) const {
121
123
size_t qty_vertex = get_VertexAmount ();
122
- return edgeMatrix[startIv* qty_vertex + endIv];
124
+ return edgeMatrix[startIv * qty_vertex + endIv];
123
125
}
124
126
125
127
bool isEdgeExist (size_t startIv, size_t endIv) const {
@@ -147,13 +149,13 @@ class Graph {
147
149
};
148
150
149
151
Vertex& get_Vertex (size_t index) {
150
- return vertices[index ];
152
+ return vertices[index ];
151
153
}
152
154
153
155
size_t get_VertexAmount () const {
154
- return vertices.size ();
156
+ return vertices.size ();
155
157
}
156
-
158
+
157
159
158
160
size_t add_Vertex (Data vertex_data) {
159
161
size_t index = vertices.size ();
@@ -181,7 +183,7 @@ class Graph {
181
183
return ;
182
184
}
183
185
184
-
186
+
185
187
for (size_t i = 0 ; i < qty_vertex; ++i) {
186
188
Edge* edge = edgeMatrix.get (index * qty_vertex + i);
187
189
if (edge) {
@@ -193,7 +195,7 @@ class Graph {
193
195
}
194
196
}
195
197
196
-
198
+
197
199
Vector<Edge*> TimeMatrix;
198
200
TimeMatrix.resize ((qty_vertex - 1 ) * (qty_vertex - 1 ));
199
201
@@ -230,7 +232,7 @@ class Graph {
230
232
Graph* graph;
231
233
size_t start;
232
234
size_t end;
233
-
235
+
234
236
size_t get_index_Vertex_near () {
235
237
for (size_t i = end + 1 ; i < graph->get_VertexAmount (); i++) {
236
238
if (graph->isEdgeExist (start, i)) {
@@ -274,12 +276,12 @@ class Graph {
274
276
275
277
276
278
277
-
279
+
278
280
private:
279
281
void clearEdges () {
280
282
for (size_t i = 0 ; i < edgeMatrix.size (); i++) {
281
283
delete edgeMatrix.get (i);
282
- edgeMatrix.set (i, nullptr );
284
+ edgeMatrix.set (i, nullptr );
283
285
}
284
286
}
285
287
Vector<Vertex> vertices;
0 commit comments