Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. template<typename vertex>
  2. class directed_graph
  3. {
  4. private:
  5. std::vector<std::vector<bool> > adj_matrix;
  6. size_t size;
  7. int num_of_vertices;
  8.  
  9. public:
  10. void add_vertex(const vertex&);
  11. void add_edge(const vertex&, const vertex&);
  12. }
  13.  
  14.  
  15. template <typename vertex>
  16. void directed_graph<vertex>::add_vertex(const vertex& u)
  17. {
  18. int newVertexNumber = num_of_vertices;
  19. num_of_vertices++;
  20.  
  21. for(int i = 0; i<num_of_vertices; i++)
  22. {
  23. adj_matrix[i][newVertexNumber] = false;
  24. adj_matrix[newVertexNumber][i] = false;
  25. }
  26.  
  27. newVertexNumber = u;
  28.  
  29. }
  30.  
  31.  
  32. template <typename vertex>
  33. void directed_graph<vertex>::add_edge(const vertex& u, const vertex& v)
  34. {
  35. if ((u >= 0) && (u < size) && (v >= 0) && (v < size) && (u != v))
  36. {
  37. adj_matrix[u][v] = true;
  38. adj_matrix[v][u] = true;
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement