public class DepthFirstOrder extends java.lang.Object
Digraph,
EdgeWeightedDigraph,
DirectedEdge,
Queue, and
Stack.| Constructor and Description |
|---|
DepthFirstOrder(Digraph G)
Constructor.
|
DepthFirstOrder(EdgeWeightedDigraph G) |
| Modifier and Type | Method and Description |
|---|---|
static void |
main(java.lang.String[] args)
Receives, on the command-line, the name of a file
containing the description of a digraph or an edge-weighted digraph
(but ignores the weights of the edges).
|
java.lang.Iterable<java.lang.Integer> |
post()
Returns vertices in postorder as an Iterable.
|
int |
post(int v)
Returns the postorder number of vertex v.
|
java.lang.Iterable<java.lang.Integer> |
pre()
Returns vertices in preorder as an Iterable.
|
int |
pre(int v)
Returns the preorder number of vertex v.
|
java.lang.Iterable<java.lang.Integer> |
reversePost() |
public DepthFirstOrder(Digraph G)
Implementation details: The method calls dfs(), where most of the work is done.)
public DepthFirstOrder(EdgeWeightedDigraph G)
public int pre(int v)
public int post(int v)
public java.lang.Iterable<java.lang.Integer> post()
public java.lang.Iterable<java.lang.Integer> pre()
public java.lang.Iterable<java.lang.Integer> reversePost()
public static void main(java.lang.String[] args)
Here is the result of a sample run:
% java DepthFirstOrder tinyDAG.txt
v pre post
--------------
0 0 8
1 3 2
2 9 10
3 10 9
4 2 0
5 1 1
6 4 7
7 11 11
8 12 12
9 5 6
10 8 5
11 6 4
12 7 3
Preorder: 0 5 4 1 6 9 11 12 10 2 3 7 8
Postorder: 4 5 1 12 11 10 9 6 0 3 2 7 8
Reverse postorder: 8 7 2 3 0 6 9 10 11 12 1 5 4
Data files may be found in
http://algs4.cs.princeton.edu/42directed/tinyDAG.txt
and
http://algs4.cs.princeton.edu/42directed/tinyDG.txt