Skip to content

Methods

Matthew Mawby edited this page Dec 29, 2016 · 2 revisions
Modifier and Type Method and Description
boolean public boolean addNode(N name)
Adds a node with the given name to the graph.
boolean public boolean addEdge(N to, N from, E label)
Adds an edge between the given nodes with the specified edge label.
int public int size()
Returns the number of nodes in the graph.
int public int edgeCount()
Returns the number of edges in the graph.
boolean public boolean contains(N node_label)
Returns true if the graph contains the specified node.
HashSet<N> public HashSet getNodes()
Returns a HashSet containing all the nodes in the graph.
HashMap<E,Integer> public HashMap<E,Integer> getEdges()
Returns a HashMap where the keys are all of the edges in the graph and the values are the number of times that edge occurs in the graph.
HashSet<N> public HashSet getNeighborsTo(N node_label)
Returns a HashSet of all the nodes that can be reached from the given node.
HashSet<N> public HashSet getNeighborsFrom(N node_label)
Returns a HashSet of all the nodes that you can reach the given node from.
ArrayList<N> public ArrayList shortestPath(N source, N destination)
Returns an ArrayList of nodes representing the path from specified source node to the specified destination node. Non-Numeric edge labels are treated as having equal weight.
HashMap<N,Double> public HashMap<N,Double> shortestPathTree(N source)
Returns a HashMap where the keys are node labels and the values are the distances to that node from the source node.

Clone this wiki locally