Skip to content

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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

Lepsps
Copy link
Collaborator

@Lepsps Lepsps commented Dec 18, 2024

No description provided.

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
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 on lines 137 to 138
//for (int i : traversal_order)
// std::cout << i << " ";
Copy link
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

CMakeLists.txt Outdated
@@ -1,15 +1,19 @@
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.15)
Copy link
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 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
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 on lines 33 to 34
int vertexCount() const;
int edgeCount() const;
Copy link
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"


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

Copy link
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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants