/*
* The subroutine of DFS. NOTE: the set is used to distinguish between 1st
* and 2nd round of DFS. set == null: finished vertices are stored (1st
* round). set != null: all vertices found will be saved in the set (2nd
* round)
*/
private void dfsVisit(DirectedGraph graph, VertexData vertexData, SupportClass.SetSupport vertices)
{
System.Collections.ArrayList stack = new System.Collections.ArrayList();
stack.Add(vertexData);
while (!(stack.Count == 0))
{
VertexData data = (VertexData)SupportClass.StackSupport.Pop(stack);
if (!data.m_discovered)
{
data.m_discovered = true;
if (vertices != null)
{
vertices.Add(data.m_vertex);
}
// TODO: other way to identify when this vertex is finished!?
stack.Add(new VertexData(this, data, true, true));
// follow all edges
System.Collections.IEnumerator iter = graph.outgoingEdgesOf(data.m_vertex).GetEnumerator();
//UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
while (iter.MoveNext())
{
//UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
DirectedEdge edge = (DirectedEdge)iter.Current;
VertexData targetData = (VertexData)m_vertexToVertexData[edge.Target];
if (!targetData.m_discovered)
{
// the "recursion"
stack.Add(targetData);
}
}
}
else if (data.m_finished)
{
if (vertices == null)
{
// see TODO above
m_orderedVertices.Insert(0, data.m_vertex);
}
}
}
}