Skip to content

Commit

Permalink
lab 4 update
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-anastasiia committed Nov 25, 2024
1 parent 278448a commit d5de9ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
4 changes: 2 additions & 2 deletions LibraryCPPTemplate/Tests/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ int main() {
}

//////////Vertex removal check//////////////////////////////////////////
/*graph.add_Edge(2, 3, 5);
graph.add_Edge(2, 3, 5);
graph.add_Edge(0, 4, 1);

int index1 = 3;
Expand All @@ -153,7 +153,7 @@ int main() {
}
else {
std::cout << "valid vertex removal" << std::endl;
}*/
}


return 0;
Expand Down
38 changes: 16 additions & 22 deletions LibraryCPPTemplate/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,18 @@ class Graph {
return index;
}


void remove_Vertex(size_t index) {
size_t qty_vertex = get_VertexAmount();
size_t qty_vertex = get_VertexAmount();
if (index >= qty_vertex) {
return;
}

for (size_t i = index; i < qty_vertex - 1; i++) {
vertices.set(i, vertices.get(i + 1));
}
vertices.resize(qty_vertex - 1);

for (size_t i = 0; i < qty_vertex; ++i) {
for (size_t i = 0; i < qty_vertex; i++) {
Edge* edge = edgeMatrix.get(index * qty_vertex + i);
if (edge) {
delete edge;
Expand All @@ -195,29 +198,20 @@ class Graph {
}
}


Vector<Edge*> TimeMatrix;
TimeMatrix.resize((qty_vertex - 1) * (qty_vertex - 1));

size_t newIndex = 0;
for (size_t i = 0; i < qty_vertex; ++i) {
if (i == index) continue;

size_t newInnerIndex = 0;
for (size_t j = 0; j < qty_vertex; ++j) {
if (j == index) continue;

Edge* edge = edgeMatrix.get(i * qty_vertex + j);
TimeMatrix.set(newIndex * (qty_vertex - 1) + newInnerIndex, edge ? new Edge(*edge) : nullptr);
newInnerIndex++;
Vector<Edge*> TimeEdgeMatrix;
size_t qty_vertex1 = get_VertexAmount();

TimeEdgeMatrix.resize(qty_vertex1 * qty_vertex1);
for (size_t i = 0; i < qty_vertex1; i++) {
for (size_t j = 0; j < qty_vertex1; j++) {
Edge* edge = edgeMatrix.get(((i + (i >= index)) * qty_vertex) + (j + (j >= index)));
TimeEdgeMatrix.set((i * qty_vertex1) + j, edge);
}
newIndex++;
}

edgeMatrix.swap_data(TimeMatrix);
vertices.resize(qty_vertex - 1);
}
edgeMatrix.swap_data(TimeEdgeMatrix);

}

std::vector<int> get_AllVertexData() const {
std::vector<int> allData;
Expand Down

0 comments on commit d5de9ee

Please sign in to comment.