Package dsa
Class DFSOrders
- java.lang.Object
-
- dsa.DFSOrders
-
public class DFSOrders extends Object
An immutable data type to determine depth-first orders (pre, post, and reverse post) for a digraph.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
main(String[] args)
Unit tests the data type.Iterable<Integer>
post()
Returns the vertices in post-order.int
post(int v)
Returns the post-order number of vertex v.Iterable<Integer>
pre()
Returns the vertices in pre-order.int
pre(int v)
Returns the pre-order number of vertex v.Iterable<Integer>
reversePost()
Returns the vertices in reverse post-order.
-
-
-
Constructor Detail
-
DFSOrders
public DFSOrders(DiGraph G)
Determines depth-first orders (pre, post, and reverse post) for the digraph G.- Parameters:
G
- the digraph.
-
-
Method Detail
-
pre
public int pre(int v)
Returns the pre-order number of vertex v.- Parameters:
v
- the vertex.- Returns:
- the pre-order number of vertex v.
-
post
public int post(int v)
Returns the post-order number of vertex v.- Parameters:
v
- the vertex.- Returns:
- the post-order number of vertex v.
-
pre
public Iterable<Integer> pre()
Returns the vertices in pre-order.- Returns:
- the vertices in pre-order.
-
post
public Iterable<Integer> post()
Returns the vertices in post-order.- Returns:
- the vertices in post-order.
-
reversePost
public Iterable<Integer> reversePost()
Returns the vertices in reverse post-order.- Returns:
- the vertices in reverse post-order.
-
main
public static void main(String[] args)
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-
-