Skip to content

Commit 3aa158c

Browse files
committed
lab4 update
1 parent fe30abf commit 3aa158c

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

LibraryCPPTemplate/graph.h

+18-16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <vector>
55
#include <stdexcept>
66

7+
78
template<typename Data>
89
class Graph {
910
public:
@@ -44,12 +45,12 @@ class Graph {
4445
return *this;
4546
}
4647
clearEdges();
47-
48+
4849
vertices = other.vertices;
4950
edgeMatrix.resize(other.edgeMatrix.size());
5051
for (size_t i = 0; i < other.edgeMatrix.size(); ++i) {
5152
if (other.edgeMatrix[i] != nullptr) {
52-
edgeMatrix[i] = new Edge(*other.edgeMatrix[i]);
53+
edgeMatrix[i] = new Edge(*other.edgeMatrix[i]);
5354
}
5455
else {
5556
edgeMatrix[i] = nullptr;
@@ -82,16 +83,16 @@ class Graph {
8283
Edge*& exists_edge = edgeMatrix[startIv * qty_vertex + endIv];
8384

8485
if (exists_edge != nullptr) {
85-
delete exists_edge;
86+
delete exists_edge;
8687
}
8788

8889
exists_edge = new Edge(edge_data);
8990

9091
if (type == GraphType::Undirected) {
9192
Edge*& exists_ReverseEdge = edgeMatrix[endIv * qty_vertex + startIv];
92-
93+
9394
if (exists_ReverseEdge != nullptr) {
94-
delete exists_ReverseEdge;
95+
delete exists_ReverseEdge;
9596
}
9697

9798
exists_ReverseEdge = new Edge(edge_data);
@@ -100,16 +101,17 @@ class Graph {
100101

101102

102103

104+
103105
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()) {
105107
throw std::out_of_range("Vertex index out of range.");
106108
}
107109

108110
size_t index = startIv * get_VertexAmount() + endIv;
109111
delete edgeMatrix[index];
110112
edgeMatrix[index] = nullptr;
111113

112-
114+
113115
if (type == GraphType::Undirected) {
114116
size_t reverse_Index = endIv * get_VertexAmount() + startIv;
115117
delete edgeMatrix[reverse_Index];
@@ -119,7 +121,7 @@ class Graph {
119121

120122
Edge* get_Edge(size_t startIv, size_t endIv) const {
121123
size_t qty_vertex = get_VertexAmount();
122-
return edgeMatrix[startIv* qty_vertex + endIv];
124+
return edgeMatrix[startIv * qty_vertex + endIv];
123125
}
124126

125127
bool isEdgeExist(size_t startIv, size_t endIv) const {
@@ -147,13 +149,13 @@ class Graph {
147149
};
148150

149151
Vertex& get_Vertex(size_t index) {
150-
return vertices[index];
152+
return vertices[index];
151153
}
152154

153155
size_t get_VertexAmount() const {
154-
return vertices.size();
156+
return vertices.size();
155157
}
156-
158+
157159

158160
size_t add_Vertex(Data vertex_data) {
159161
size_t index = vertices.size();
@@ -181,7 +183,7 @@ class Graph {
181183
return;
182184
}
183185

184-
186+
185187
for (size_t i = 0; i < qty_vertex; ++i) {
186188
Edge* edge = edgeMatrix.get(index * qty_vertex + i);
187189
if (edge) {
@@ -193,7 +195,7 @@ class Graph {
193195
}
194196
}
195197

196-
198+
197199
Vector<Edge*> TimeMatrix;
198200
TimeMatrix.resize((qty_vertex - 1) * (qty_vertex - 1));
199201

@@ -230,7 +232,7 @@ class Graph {
230232
Graph* graph;
231233
size_t start;
232234
size_t end;
233-
235+
234236
size_t get_index_Vertex_near() {
235237
for (size_t i = end + 1; i < graph->get_VertexAmount(); i++) {
236238
if (graph->isEdgeExist(start, i)) {
@@ -274,12 +276,12 @@ class Graph {
274276

275277

276278

277-
279+
278280
private:
279281
void clearEdges() {
280282
for (size_t i = 0; i < edgeMatrix.size(); i++) {
281283
delete edgeMatrix.get(i);
282-
edgeMatrix.set(i, nullptr);
284+
edgeMatrix.set(i, nullptr);
283285
}
284286
}
285287
Vector<Vertex> vertices;

0 commit comments

Comments
 (0)