I am implementing stack for dfs traversal, I am trying to give time stamps for each node, timestamp is given only when a node is new(start_time) or when we are done with that node i.e., no other new nodes can be traversed from that node, this time is finish_time i am not getting as expected and I am not finding my way efficient to store this.
I am considering UNDIRECTED GRAPH Suppose there are 6 nodes and 8 edges connecting them,
6
8
1 2
2 3
1 3
1 4
2 4
2 5
3 5
3 6
when a node is not visited, I am putting it into stack and traversing all its adjacent nodes, if adjacent nodes all visited , I am increasing counter and after the loop I am checking If no nodes are visited in the loop, that means the the node has no other path left so I am popping it out from stack.
here is MY CODE