Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. struct node {
  5. int id;
  6. std::vector<node*> connected_nodes;
  7. };
  8.  
  9. class graph {
  10. std::vector<node*> all_nodes;
  11. bool check_connect(int, int);
  12. };
  13.  
  14. bool graph::check_connect(int id1, int id2) {
  15. for (size_t i = 0; i < all_nodes.size(); i++) {
  16. if (all_nodes[i]->id == id1) {
  17. for (size_t j = 0; j < all_nodes[i]->connected_nodes.size(); j++) {
  18. if (all_nodes[i]->connected_nodes[j]->id == id2) {
  19. return 1;
  20. }
  21. }
  22. }
  23. }
  24. return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement