56void addEdge(std::vector<std::vector<size_t>> *adj,
size_t u,
size_t v) {
64 (*adj)[u - 1].push_back(v - 1);
65 (*adj)[v - 1].push_back(u - 1);
80void explore(
const std::vector<std::vector<size_t>> &adj,
size_t v,
81 std::vector<bool> *visited) {
82 std::cout << v + 1 <<
" ";
84 for (
auto x : adj[v]) {
101 size_t vertices = adj.size();
103 std::vector<bool> visited(vertices,
false);
110 size_t vertices = 0, edges = 0;
111 std::cout <<
"Enter the Vertices : ";
112 std::cin >> vertices;
113 std::cout <<
"Enter the Edges : ";
117 std::vector<std::vector<size_t>> adj(vertices, std::vector<size_t>());
120 std::cout <<
"Enter the vertices which have edges between them : "
129 graph::depth_first_search(adj, 2);
131 std::cout << std::endl;
Functions for Depth First Search algorithm.
void explore(const std::vector< std::vector< int > > *adj, int u, std::vector< bool > *visited)
Utility function for depth first seach algorithm this function explores the vertex which is passed in...
void addEdge(std::vector< std::vector< int > > *adj, int u, int v)
Function that add edge between two nodes or vertices of graph.