-
Notifications
You must be signed in to change notification settings - Fork 5
added a graph class #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
src/graph/graph.cpp
Outdated
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; |
There was a problem hiding this comment.
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?
src/graph/graph.cpp
Outdated
//for (int i : traversal_order) | ||
// std::cout << i << " "; |
There was a problem hiding this comment.
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
CMakeLists.txt
Outdated
@@ -1,15 +1,19 @@ | |||
cmake_minimum_required(VERSION 3.20) | |||
cmake_minimum_required(VERSION 3.15) |
There was a problem hiding this comment.
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?
src/graph/graph.cpp
Outdated
void Graph::getVertex() const { | ||
if (!this->empty()) { | ||
for (const auto& vertice : vertices_) { | ||
std::cout << vertice.first << " "; | ||
} | ||
std::cout << '\n'; | ||
} | ||
} |
There was a problem hiding this comment.
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
include/graph/graph.h
Outdated
int vertexCount() const; | ||
int edgeCount() const; |
There was a problem hiding this comment.
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"
|
||
#include "graph/graph.h" | ||
#include "gtest/gtest.h" | ||
|
There was a problem hiding this comment.
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.
No description provided.