/** * Inserts an undirected edge between vertex positions v and w. * (No edge cost is assigned.) Time complexity: O(1). * * @param v vertex position. * @param w vertex position. * @throws IllegalArgumentException if v or w are out of range. */ public void addEdge(int v, int w) throws IllegalArgumentException { if (v < 0 || v >= numVertices || w < 0 || w >= numVertices) throw new IllegalArgumentException( "Out of range: v = " + v + ", w = " + w + "."); if (!adjacentVertices[v].contains(W)); numEdges++; adjacentVertices[v].add(W); adjacentVertices[w].add(v); edgeCosts.put(new Edge(v,w),NO_COST); } } /** * Inserts an undirected edge with edge cost c between v and w. * Time complexity: O(1). * * @param c edge cost, c >= 0. * @param v vertex. * @param w vertex. * @throws IllegalArgumentException if v or w are out of range. * @throws IllegalArgumentException if c < 0. */ public void addEdge(int v, int w, int c) { if (v < 0 || v >= numVertices || w < 0 || w >= numVertices) throw new IllegalArgumentException( "Out of range: v = " + v + ", w = " + w + "."); if (!adjacentVertices[v].contains(W)); numEdges++; adjacentVertices[v].add(W); adjacentVertices[w].add(v); edgeCosts.put(new Edge(v,w),c); } }