Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

added a graph class#17

Open
Lepsps wants to merge 17 commits intoembedded-dev-research:mainfrom
Lepsps:shekhirev_vlad
Open

added a graph class#17
Lepsps wants to merge 17 commits intoembedded-dev-research:mainfrom
Lepsps:shekhirev_vlad

Conversation

@Lepsps
Copy link
Copy Markdown
Collaborator

@Lepsps Lepsps commented Dec 18, 2024

No description provided.

Comment thread src/graph/graph.cpp Outdated
Comment on lines +94 to +111
bool Graph::hasPath(int u, int v) {
if (vertices.find(u) != vertices.end() && vertices.find(v) != vertices.end()) {
std::unordered_map <int, bool> visited;
std::queue<int> queue;
queue.push(u);

while (!queue.empty()) {
int current = queue.front();
queue.pop();
if (current == v) { return true; }
visited[current] = true;

for (const int& neighbor : vertices[current]->getNeighbors())
if (!visited[neighbor])
queue.push(neighbor);

}
return false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reuse the code in hasPath and BFS?

Comment thread src/graph/graph.cpp Outdated
Comment on lines +137 to +138
//for (int i : traversal_order)
// std::cout << i << " ";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove all commented out code in the final version

Comment thread CMakeLists.txt Outdated
@@ -1,15 +1,19 @@
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.15)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to be lowered?

Comment thread src/graph/graph.cpp Outdated
Comment on lines +39 to +46
void Graph::getVertex() const {
if (!this->empty()) {
for (const auto& vertice : vertices_) {
std::cout << vertice.first << " ";
}
std::cout << '\n';
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this function does not give a vertex, it only prints some messages

Comment thread include/graph/graph.h Outdated
Comment on lines +33 to +34
int vertexCount() const;
int edgeCount() const;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to name them as "get"

Comment thread test/graph/test_graph.cpp

#include "graph/graph.h"
#include "gtest/gtest.h"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for ASSERT_NO_THROW:

It seems you're generally not using exceptions. I think it is better to check some data about the graph in the assertion part. For example, if you have added one vertex, you can check that amount of vertices in the graph is 1.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants