Skip to content

Commit 47abe53

Browse files
committed
lab 4 update
1 parent fa3f14d commit 47abe53

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

LibraryCPPTemplate/Tests/graph.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ int main() {
141141
}
142142

143143
//////////Vertex removal check//////////////////////////////////////////
144-
/*graph.add_Edge(2, 3, 5);
145-
graph.add_Edge(0, 4, 1);*/
144+
graph.add_Edge(0, 1, 10);
145+
graph.add_Edge(2, 3, 5);
146+
graph.add_Edge(0, 4, 1);
146147

147148
int index1 = 3;
148149
std::cout << "Deleting a vertex with an index: " << index1 << std::endl;

LibraryCPPTemplate/graph.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ class Graph {
2424
}
2525

2626
~Graph() {
27-
for (size_t i = 0; i < edgeMatrix.size(); ++i) {
28-
delete edgeMatrix[i];
29-
edgeMatrix[i] = nullptr;
27+
size_t qty_vertex = get_VertexAmount();
28+
for (size_t i = 0; i < qty_vertex; ++i) {
29+
for (size_t j = 0; j < qty_vertex; ++j) {
30+
delete edgeMatrix[i * qty_vertex + j];
31+
edgeMatrix[i * qty_vertex + j] = nullptr;
32+
}
3033
}
3134
}
3235

36+
3337
Graph(const Graph& a) : type(a.type), vertices(a.vertices) {
3438
edgeMatrix.resize(a.edgeMatrix.size());
3539
for (size_t i = 0; i < a.edgeMatrix.size(); ++i) {

0 commit comments

Comments
 (0)