/** 一个常规的无向图。For any given concrete extension of * this class, a different subset of the operations listed will work. * For uniformity, we take all vertices to be numbered with integers * between 0 and N-1. */
publicinterfaceGraph{
/** 顶点的数量。顶点的编号从0到numVertices()-1。*/
intnumVertices();
/** 边的数量。边的编号从0到numEdges()-1。 */
intnumEdges();
/** 和边e连接的顶点。node0是编号较小的顶点。 */
intnode0(inte);intnode1(inte);
/** v0和v1是否相邻,是则返回true。 */
booleanisEdge(intv0,intv1);
/** 顶点#v的度(和顶点#v连接的边的数量)。 */
intdegree(intv);
/** The number of the Kth edge incident on V, 0<=k<degree(V). */
intincident(intv,intk);
}
/** The Kth node adjacent to V, * intended that adjacent(v,k) * or node1(incident(v,k)). */
intadjacent(intv,intk);
/** Add M initially unconnected void addVertices(int M);
0<=K<outDegree(V). It is
= either node0(incident(v,k))
vertices to this graph. */
/** Add an (undirected) edge between V0 and V1. */
voidaddEdge(intv0,intv1);
/** Remove all edges involving vertex V from this graph. */voidremoveEdges(intv);
/** Remove the (undirected) edge (v0, v1) from this graph. */voidremoveEdge(intv0,intv1);
}
```
图12.4:无向图类的简单抽象(java描述)
```java
/** A digraph */
publicclassAdjGraphimplementsDigraph{
/** A new Digraph with N unconnected vertices */publicAdjGraph(intN){