Commit b3303a34 authored by Asal Asgari's avatar Asal Asgari
Browse files

DFS Finished code and passed all the unit tests! ^_^

parent a7c4fc32
......@@ -16,7 +16,38 @@ namespace dte3603::graph::algorithms
[[maybe_unused]]
typename Graph_T::vertex_descriptor const& start)
{
return {};
using VertexDescriptor = typename Graph_T::vertex_descriptor;
auto v = VertexDescriptor();
std::vector<VertexDescriptor> visited;
std::pair<boost::adjacency_list<>::vertex_iterator,
boost::adjacency_list<>::vertex_iterator> vs = boost::vertices(graph);
std::stack<VertexDescriptor> stack;
std::vector<VertexDescriptor> Nodes;
v = start;
visited.push_back(start);
stack.push(start);
while(!stack.empty())
{
bool pop_time = true;
auto v = stack.top();
auto adj_verts = boost::adjacent_vertices(v, graph);
for (auto i = adj_verts.first; i != adj_verts.second; i++)
{
auto u = *i;
if(!(std::find(visited.begin(), visited.end(), u) != visited.end()))
{
pop_time = false;
visited.push_back(u);
stack.push(u);
Nodes.push_back(u);
break;
}
}
if(pop_time)
stack.pop();
}
return Nodes;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment