- making comments javadocs, adding some braces.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/sandbox/graph/trunk@144584 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
1 parent
71a051a08e
commit
adb5d71087
1 file changed
+23
-4
@@ -65,22 +65,37 @@ import org.apache.commons.graph.VStack;
|
||||
* this class (and of course its descendants) may be passed to a DFS
|
||||
* object.
|
||||
*
|
||||
* @version $Id: DFSVisitor.java,v 1.1 2001/11/29 14:17:34 jvanzyl Exp $
|
||||
* @version $Id: DFSVisitor.java,v 1.2 2001/12/01 19:12:14 jvanzyl Exp $
|
||||
* @author <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
|
||||
* @see DFS
|
||||
*/
|
||||
public class DFSVisitor extends DefaultVisitor {
|
||||
private int time; // Global time
|
||||
private VStack stack; // Stack to remember predecessors
|
||||
|
||||
/**
|
||||
* Global time.
|
||||
*/
|
||||
private int time;
|
||||
|
||||
/**
|
||||
* Stack to remember predecessors.
|
||||
*/
|
||||
private VStack stack;
|
||||
|
||||
public DFSVisitor() {}
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public DFSVisitor()
|
||||
{
|
||||
}
|
||||
|
||||
public void discoverGraph(Graph g) {
|
||||
int size = g.getNoVertices();
|
||||
Vertex[] vertices = g.getVertexArray();
|
||||
|
||||
for(int i=0; i < size; i++)
|
||||
{
|
||||
vertices[i].setPredecessor(null);
|
||||
}
|
||||
|
||||
time = 0; // Reset timer
|
||||
stack = new VStack(size);
|
||||
@@ -88,9 +103,13 @@ public class DFSVisitor extends DefaultVisitor {
|
||||
|
||||
public void discoverVertex(Vertex v) {
|
||||
if(stack.empty()) // First node
|
||||
{
|
||||
v.setPredecessor(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
v.setPredecessor(stack.top());
|
||||
}
|
||||
|
||||
stack.push(v);
|
||||
v.setDiscoveryTime(time++);
|
||||
|
||||
Reference in new issue
Block a user