Пример #1
0
 /**
  * Adds the undirected edge v-w to this graph.
  *
  * @param v one vertex in the edge
  * @param w the other vertex in the edge
  * @throws IndexOutOfBoundsException unless both 0 <= v < V and 0 <= w < V
  */
 public void addEdge(int v, int w) {
   validateVertex(v);
   validateVertex(w);
   E++;
   adj[v].add(w);
   adj[w].add(v);
 }
Пример #2
0
 /**
  * Returns the degree of vertex <tt>v</tt>.
  *
  * @param v the vertex
  * @return the degree of vertex <tt>v</tt>
  * @throws IndexOutOfBoundsException unless 0 <= v < V
  */
 public int degree(int v) {
   validateVertex(v);
   return adj[v].size();
 }
Пример #3
0
 /**
  * Returns the vertices adjacent to vertex <tt>v</tt>.
  *
  * @param v the vertex
  * @return the vertices adjacent to vertex <tt>v</tt>, as an iterable
  * @throws IndexOutOfBoundsException unless 0 <= v < V
  */
 public Iterable<Integer> adj(int v) {
   validateVertex(v);
   return adj[v];
 }