Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename vertex>
- class directed_graph
- {
- private:
- std::vector<std::vector<bool> > adj_matrix;
- size_t size;
- int num_of_vertices;
- public:
- void add_vertex(const vertex&);
- void add_edge(const vertex&, const vertex&);
- }
- template <typename vertex>
- void directed_graph<vertex>::add_vertex(const vertex& u)
- {
- int newVertexNumber = num_of_vertices;
- num_of_vertices++;
- for(int i = 0; i<num_of_vertices; i++)
- {
- adj_matrix[i][newVertexNumber] = false;
- adj_matrix[newVertexNumber][i] = false;
- }
- newVertexNumber = u;
- }
- template <typename vertex>
- void directed_graph<vertex>::add_edge(const vertex& u, const vertex& v)
- {
- if ((u >= 0) && (u < size) && (v >= 0) && (v < size) && (u != v))
- {
- adj_matrix[u][v] = true;
- adj_matrix[v][u] = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement