127 std::cout <<
"Case 1: " << std::endl;
129 std::vector<std::vector<size_t> > g1(3, std::vector<size_t>());
131 graph::depth_first_search::addEdge(&g1, 1, 2);
132 graph::depth_first_search::addEdge(&g1, 2, 3);
133 graph::depth_first_search::addEdge(&g1, 3, 1);
135 std::vector<size_t> expected1 {1, 2, 3};
136 assert(graph::depth_first_search::dfs(g1, start_pos - 1) == expected1);
137 std::cout <<
"Passed" << std::endl;
140 std::cout <<
"Case 2: " << std::endl;
142 std::vector<std::vector<size_t> > g2(4, std::vector<size_t>());
144 graph::depth_first_search::addEdge(&g2, 1, 2);
145 graph::depth_first_search::addEdge(&g2, 1, 3);
146 graph::depth_first_search::addEdge(&g2, 2, 4);
147 graph::depth_first_search::addEdge(&g2, 4, 1);
149 std::vector<size_t> expected2 {1, 3, 2, 4};
150 assert(graph::depth_first_search::dfs(g2, start_pos - 1) == expected2);
151 std::cout <<
"Passed" << std::endl;
154 std::cout <<
"Case 3: " << std::endl;
156 std::vector<std::vector<size_t> > g3(4, std::vector<size_t>());
158 graph::depth_first_search::addEdge(&g3, 1, 2);
159 graph::depth_first_search::addEdge(&g3, 1, 3);
160 graph::depth_first_search::addEdge(&g3, 2, 4);
161 graph::depth_first_search::addEdge(&g3, 4, 1);
163 std::vector<size_t> expected3 {2, 4, 1, 3};
164 assert(graph::depth_first_search::dfs(g3, start_pos - 1) == expected3);
165 std::cout <<
"Passed" << std::endl;
176 size_t vertices = 0, edges = 0, start_pos = 1;
177 std::vector<size_t> traversal;
179 std::cout <<
"Enter the Vertices : ";
180 std::cin >> vertices;
181 std::cout <<
"Enter the Edges : ";
185 std::vector<std::vector<size_t> > adj(vertices, std::vector<size_t>());
188 std::cout <<
"Enter the vertices which have edges between them : " << std::endl;
192 graph::depth_first_search::addEdge(&adj, u, v);
196 std::cout <<
"Enter the starting vertex [1,n]: " << std::endl;
197 std::cin >> start_pos;
199 traversal = graph::depth_first_search::dfs(adj, start_pos);
202 for (
auto x : traversal) {
203 std::cout << x <<
' ';