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
My Question:
-
In the code as start_time is set to 12 which is wrong it should be 0, so how can I set it to zero instead of 12.
-
I am using count in my program to check every time weather any node can be visited from the current node,I am unable to do this without
count
variable, how can I do this as in recursive we dont use any such count, start_time[] is filled before recursive function is called and end_time[] after the call.