Reading material

Chapter 9 up to Section 9.2.3

Additional material

SimpleUndirectedGraph.java

Partial edge list implementation of SimpleUndirectedGraph:

public class Edge {
    public Object element;
    public int degree;
}
public class Vertex {
    public Object element;
    public Vertex[] vertices;
}

private Sequence vertSeq;
private Sequence edgeSeq;

public int numVertices() {
    return vertSeq.size();
}
public int numEdges() {
    return edgeSeq.size();
}
public Enumeration vertices() {
    return vertSeq.elements();
}
public Enumeration edges() {
    return edgeSeq.elements();
}
public int degree(Vertex vertex) {
    return vertex.degree;
}
public Vertex[] endVertices(Edge edge);  
    return edge.vertices;
}
public Edge insertEdge(Vertex vertex1, Vertex vertex2, Object element) {
    Edge edge = new Edge();
    edge.element = element;
    edge.vertices = new Vertex[2];
    edge.vertices[0] = vertex1;
    edge.vertices[1] = vertex2;
    vertex1.degree++;
    vertex2.degree++;
    insert edge in edgeSeq;
    return edge;
}
public Vertex insertVertex(Object element) {
    Vertex vertex = new Vertex();
    vertex.element = element;
    vertex.degree = 0;
    insert vertex in vertSeq;
    return vertex;
}
public Enumeration adjacentVertices(vertex vertex) {
    Vector vector = new Vector();
    Enumeration edges = edges();
    while(edges.hasMoreElements()) {
        Edge edge = edges.nextElement();
        if (edge.vertices[0] == vertex) {
            vector.addElement(edge.vertices[1]);
        } else if (edge.vertices[1] == vertex) {
            vector.addElement(edge.vertices[0]);
        }
    }
    return vector.elements();
}
Partial adjacency list implementation of SimpleUndirectedGraph:
public class Vertex {
    public Object element;
    public Vertex[] vertices;
    public Sequence incidentEdges;
}

public Enumeration adjacentVertices(vertex vertex) {
    Vector vector = new Vector();
    Enumeration edges = vertex.incidentEdges.elements();
    while(edges.hasMoreElements()) {
        Edge edge = edges.nextElement();
        if (edge.vertices[0] == vertex) {
            vector.addElement(edge.vertices[1]);
        } else if (edge.vertices[1] == vertex) {
            vector.addElement(edge.vertices[0]);
        }
    }
    return vector.elements();
}