类 SymbolGraph
- java.lang.Object
 - 
- edu.princeton.cs.algs4.SymbolGraph
 
 
- 
public class SymbolGraph extends java.lang.ObjectTheSymbolGraphclass represents an undirected graph, where the vertex names are arbitrary strings. By providing mappings between string vertex names and integers, it serves as a wrapper around theGraphdata type, which assumes the vertex names are integers between 0 and V - 1. It also supports initializing a symbol graph from a file.This implementation uses an
STto map from strings to integers, an array to map from integers to strings, and aGraphto store the underlying graph. The indexOf and contains operations take time proportional to log V, where V is the number of vertices. The nameOf operation takes constant time.For additional documentation, see Section 4.1 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
 
- 
- 
构造器概要
构造器 构造器 说明 SymbolGraph(java.lang.String filename, java.lang.String delimiter)Initializes a graph from a file using the specified delimiter. 
- 
方法概要
修饰符和类型 方法 说明 booleancontains(java.lang.String s)Does the graph contain the vertex nameds?GraphG()已过时。Replaced bygraph().Graphgraph()Returns the graph assoicated with the symbol graph.intindex(java.lang.String s)已过时。Replaced byindexOf(String).intindexOf(java.lang.String s)Returns the integer associated with the vertex nameds.static voidmain(java.lang.String[] args)Unit tests theSymbolGraphdata type.java.lang.Stringname(int v)已过时。Replaced bynameOf(int).java.lang.StringnameOf(int v)Returns the name of the vertex associated with the integerv. 
 - 
 
- 
- 
构造器详细资料
- 
SymbolGraph
public SymbolGraph(java.lang.String filename, java.lang.String delimiter)Initializes a graph from a file using the specified delimiter. Each line in the file contains the name of a vertex, followed by a list of the names of the vertices adjacent to that vertex, separated by the delimiter.- 参数:
 filename- the name of the filedelimiter- the delimiter between fields
 
 - 
 
- 
方法详细资料
- 
contains
public boolean contains(java.lang.String s)
Does the graph contain the vertex nameds?- 参数:
 s- the name of a vertex- 返回:
 trueifsis the name of a vertex, andfalseotherwise
 
- 
index
@Deprecated public int index(java.lang.String s)
已过时。Replaced byindexOf(String).Returns the integer associated with the vertex nameds.- 参数:
 s- the name of a vertex- 返回:
 - the integer (between 0 and V - 1) associated with the vertex named 
s 
 
- 
indexOf
public int indexOf(java.lang.String s)
Returns the integer associated with the vertex nameds.- 参数:
 s- the name of a vertex- 返回:
 - the integer (between 0 and V - 1) associated with the vertex named 
s 
 
- 
name
@Deprecated public java.lang.String name(int v)
已过时。Replaced bynameOf(int).Returns the name of the vertex associated with the integerv.- 参数:
 v- the integer corresponding to a vertex (between 0 and V - 1)- 返回:
 - the name of the vertex associated with the integer 
v - 抛出:
 java.lang.IllegalArgumentException- unless0 <= v < V
 
- 
nameOf
public java.lang.String nameOf(int v)
Returns the name of the vertex associated with the integerv.- 参数:
 v- the integer corresponding to a vertex (between 0 and V - 1)- 返回:
 - the name of the vertex associated with the integer 
v - 抛出:
 java.lang.IllegalArgumentException- unless0 <= v < V
 
- 
G
@Deprecated public Graph G()
已过时。Replaced bygraph().Returns the graph assoicated with the symbol graph. It is the client's responsibility not to mutate the graph.- 返回:
 - the graph associated with the symbol graph
 
 
- 
graph
public Graph graph()
Returns the graph assoicated with the symbol graph. It is the client's responsibility not to mutate the graph.- 返回:
 - the graph associated with the symbol graph
 
 
- 
main
public static void main(java.lang.String[] args)
Unit tests theSymbolGraphdata type.- 参数:
 args- the command-line arguments
 
 - 
 
 -