Graph Interface: Insert Vertices
The Graph interface declares an operation that takes the data you want to store in a node, it inserts it in the Graph by creating a Vertex. The operation returns the newly created Vertex to you.
/**
* Insert a new vertex.
*
* @param v Element to insert.
* @return Vertex position created to hold element.
* @throws InsertionException If v is null or already in this Graph
*/
Vertex<V> insert(V v) throws InsertionException;
There is also an operation that returns an iterable over the vertices in the Graph.
/**
* Vertices of graph.
*
* @return Iterable over all vertices of the graph (in no specific order).
*/
Iterable<Vertex<V>> vertices();
Here is an example for printing the values stored in the vertices of a graph:
for (Vertex<V> v: graph.vertices()) {
System.out.println(v.get());
}