-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDepthFirstTraversal.java
More file actions
34 lines (27 loc) · 862 Bytes
/
DepthFirstTraversal.java
File metadata and controls
34 lines (27 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package graph;
import java.util.Collections;
import java.util.ArrayDeque;
/* See restrictions in Graph.java. */
/** Implements a depth-first traversal of a graph. Generally, the
* client will extend this class, overriding the visit and
* postVisit methods, as desired (by default, they do nothing).
* @author Rafayel Mkrtchyan
*/
public class DepthFirstTraversal extends Traversal {
/** A depth-first Traversal of G, using FRINGE as the fringe. */
protected DepthFirstTraversal(Graph G) {
super(G, Collections.asLifoQueue(new ArrayDeque<Integer>()));
}
@Override
protected boolean visit(int v) {
return super.visit(v);
}
@Override
protected boolean postVisit(int v) {
return super.postVisit(v);
}
@Override
protected boolean shouldPostVisit(int v) {
return true;
}
}