Skip to content

Commit edf9a44

Browse files
committed
lab 4 update
1 parent ec89c5e commit edf9a44

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

LibraryCPPTemplate/graph.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Graph {
4646
return *this;
4747
}
4848
for (size_t i = 0; i < edgeMatrix.size(); i++) {
49-
delete edgeMatrix.get(i);
49+
delete edgeMatrix[i];
5050
}
5151
vertices = other.vertices;
5252
edgeMatrix.resize(other.edgeMatrix.size());
@@ -82,27 +82,27 @@ class Graph {
8282
void add_Edge(size_t startIv, size_t endIv, Data edge_data) {
8383
size_t qty_vertex = get_VertexAmount();
8484

85-
Edge* exists_edge = edgeMatrix.get(startIv * qty_vertex + endIv);
85+
Edge*& exists_edge = edgeMatrix[startIv * qty_vertex + endIv];
8686

8787
if (exists_edge == nullptr) {
88-
Edge* newEdge = new Edge(edge_data);
89-
edgeMatrix.set(startIv * qty_vertex + endIv, newEdge);
88+
exists_edge = new Edge(edge_data);
9089
}
9190
else {
9291
exists_edge->set_EdgeData(edge_data);
9392
}
93+
9494
if (type == GraphType::Undirected) {
95-
Edge* exists_ReverseEdge = edgeMatrix.get(endIv * qty_vertex + startIv);
95+
Edge*& exists_ReverseEdge = edgeMatrix[endIv * qty_vertex + startIv];
9696
if (exists_ReverseEdge == nullptr) {
97-
Edge* newReverseEdge = new Edge(edge_data);
98-
edgeMatrix.set(endIv * qty_vertex + startIv, newReverseEdge);
97+
exists_ReverseEdge = new Edge(edge_data);
9998
}
10099
else {
101100
exists_ReverseEdge->set_EdgeData(edge_data);
102101
}
103102
}
104103
}
105104

105+
106106
void remove_Edge(size_t startIv, size_t endIv) {
107107
if (startIv >= get_VertexAmount() || endIv>= get_VertexAmount()) {
108108
throw std::out_of_range("Vertex index out of range.");

0 commit comments

Comments
 (0)