Skip to content
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

fix: main function bugs #2709

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions greedy_algorithms/kruskals_minimum_spanning_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ void findMinimumEdge(const int &infinity,
* @returns 0 on exit
*/
int main() {
constexpr int INFINITY = 99999;
std::array<std::array<int, 6>, 6> graph{
0, 4, 1, 4, INFINITY, INFINITY,
4, 0, 3, 8, 3, INFINITY,
1, 3, 0, INFINITY, 1, INFINITY,
4, 8, INFINITY, 0, 5, 7,
INFINITY, 3, 1, 5, 0, INFINITY,
INFINITY, INFINITY, INFINITY, 7, INFINITY, 0};
constexpr int POSITIVE_INFINITY = 99999;
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not use numeric_limits<int>::infinty(); from the cmath library?

Copy link
Author

Choose a reason for hiding this comment

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

numeric_limits::infinty() returns 0

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I forgot infinity only works for floats. What about numeric_limit::max()?

std::array<std::array<int, 6>, 6> graph = {
0, 4, 1, 4, POSITIVE_INFINITY, POSITIVE_INFINITY,
4, 0, 3, 8, 3, POSITIVE_INFINITY,
1, 3, 0, POSITIVE_INFINITY, 1, POSITIVE_INFINITY,
4, 8, POSITIVE_INFINITY, 0, 5, 7,
POSITIVE_INFINITY, 3, 1, 5, 0, POSITIVE_INFINITY,
POSITIVE_INFINITY, POSITIVE_INFINITY, POSITIVE_INFINITY, 7, POSITIVE_INFINITY, 0};
Comment on lines +58 to +65
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also this should be moved to a test function outside main


greedy_algorithms::findMinimumEdge(INFINITY, graph);
greedy_algorithms::findMinimumEdge(POSITIVE_INFINITY, graph);
return 0;
}
Loading