Source of Vertex.java


  1: package GraphPackage;
  2: import java.util.Iterator;
  3: import java.util.NoSuchElementException;
  4: import ADTPackage.*; // Classes that implement various ADTs
  5: /**
  6:  A class of vertices for a graph.
  7:  
  8:  @author Frank M. Carrano
  9:  @author Timothy M. Henry
 10:  @version 4.0
 11:  */
 12: class Vertex<T> implements VertexInterface<T>
 13: {
 14:    private T label;
 15:    private ListWithIteratorInterface<Edge> edgeList; // Edges to neighbors
 16:    private boolean visited;                          // True if visited
 17:    private VertexInterface<T> previousVertex;        // On path to this vertex
 18:    private double cost;                              // Of path to this vertex
 19:    
 20:    public Vertex(T vertexLabel)
 21:    {
 22:       label = vertexLabel;
 23:       edgeList = new LinkedListWithIterator<>();
 24:       visited = false;
 25:       previousVertex = null;
 26:       cost = 0;
 27:    } // end constructor
 28: 
 29: /* < Implementations of the vertex operations go here. >
 30:    . . . */
 31: 
 32:    protected class Edge
 33:    {
 34:       private VertexInterface<T> vertex; // Vertex at end of edge
 35:       private double weight;
 36:       
 37:       protected Edge(VertexInterface<T> endVertex, double edgeWeight)
 38:       {
 39:          vertex = endVertex;
 40:          weight = edgeWeight;
 41:       } // end constructor
 42:       
 43:       protected VertexInterface<T> getEndVertex()
 44:       {
 45:          return vertex;
 46:       } // end getEndVertex
 47:       
 48:       protected double getWeight()
 49:       {
 50:          return weight; 
 51:       } // end getWeight
 52:    } // end Edge
 53: } // end Vertex