Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- struct node {
- int id;
- std::vector<node*> connected_nodes;
- };
- class graph {
- std::vector<node*> all_nodes;
- bool check_connect(int, int);
- };
- bool graph::check_connect(int id1, int id2) {
- for (size_t i = 0; i < all_nodes.size(); i++) {
- if (all_nodes[i]->id == id1) {
- for (size_t j = 0; j < all_nodes[i]->connected_nodes.size(); j++) {
- if (all_nodes[i]->connected_nodes[j]->id == id2) {
- return 1;
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement