public class SymbolDigraph extends Object
Digraph data type, which assumes the vertex names are integers
between 0 and V - 1.
It also supports initializing a symbol digraph from a file.
This implementation uses an ST to map from strings to integers,
an array to map from integers to strings, and a Digraph to store
the underlying graph.
The index and contains operations take time
proportional to log V, where V is the number of vertices.
The name operation takes constant time.
For additional documentation, see Section 4.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
| Constructor and Description |
|---|
SymbolDigraph(String filename,
String delimiter)
Initializes a digraph from a file using the specified delimiter.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(String s)
Does the digraph contain the vertex named s?
|
Digraph |
G()
Returns the digraph assoicated with the symbol graph.
|
int |
index(String s)
Returns the integer associated with the vertex named s.
|
static void |
main(String[] args)
Unit tests the SymbolDigraph data type.
|
String |
name(int v)
Returns the name of the vertex associated with the integer v.
|
public SymbolDigraph(String filename, String delimiter)
filename - the name of the filedelimiter - the delimiter between fieldspublic boolean contains(String s)
s - the name of a vertexpublic int index(String s)
s - the name of a vertexpublic String name(int v)
v - the integer corresponding to a vertex (between 0 and V - 1)public Digraph G()
public static void main(String[] args)
Copyright © 2014. All Rights Reserved.