-
Notifications
You must be signed in to change notification settings - Fork 35
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
Add C++ solutions for Chapter 13 (Graphs) #49
base: main
Are you sure you want to change the base?
Conversation
Renamed union to unionSets because union is a reserved keyword in C++
Renamed union to unionSets because union is a reserved keyword in C++
cpp/Graphs/connect_the_dots.cpp
Outdated
} | ||
} | ||
|
||
bool unionSets(int x, int y) { |
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 rename function to match python
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.
In C++, union
is a reserved keyword and using it as an identifier will cause a compilation error. I suggest using union_
to match Python's naming. Let me know if you prefer union
or other names.
* val = 0; | ||
* neighbors = vector<GraphNode*>(); | ||
* } | ||
* GraphNode(int _val) { |
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 delete the other 2 constructors to match python
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.
Done
cpp/Graphs/merging_communities.cpp
Outdated
} | ||
} | ||
|
||
void unionSets(int x, int y) { |
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 update function name to match python
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.
In C++, union
is a reserved keyword and using it as an identifier will cause a compilation error. I suggest using union_
to match Python's naming. Let me know if you prefer union
or other names.
// start word to the end word. | ||
while (!queue.empty()) { | ||
int size = queue.size(); | ||
for (int unused = 0; unused < size; unused++) { |
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 i
is a better name than unused
in this case
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.
Done
union
was renamed tounionSets
because union is a reserved keyword in C++