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:  @author Frank M. Carrano
  8:  @author Timothy M. Henry
  9:  @version 5.0
 10:  */
 11: class Vertex<T> implements VertexInterface<T>
 12: {
 13:    private T label;
 14:    private ListWithIteratorInterface<Edge> edgeList; // Edges to neighbors
 15:    private boolean visited;                          // True if visited
 16:    private VertexInterface<T> previousVertex;        // On path to this vertex
 17:    private double cost;                              // Of path to this vertex
 18:    
 19:    public Vertex(T vertexLabel)
 20:    {
 21:       label = vertexLabel;
 22:       edgeList = new LinkedListWithIterator<>();
 23:       visited = false;
 24:       previousVertex = null;
 25:       cost = 0;
 26:    } // end constructor

 28: /* Implementations of the vertex operations go here.
 29:    . . . */

 31:    protected class Edge
 32:    {
 33:       private VertexInterface<T> vertex; // Vertex at end of edge
 34:       private double weight;
 35:       
 36:       protected Edge(VertexInterface<T> endVertex, double edgeWeight)
 37:       {
 38:          vertex = endVertex;
 39:          weight = edgeWeight;
 40:       } // end constructor
 41:       
 42:       protected Edge(VertexInterface<T> endVertex)
 43:       {
 44:          vertex = endVertex;
 45:          weight = 0;
 46:       } // end constructor

 48:       protected VertexInterface<T> getEndVertex()
 49:       {
 50:          return vertex;
 51:       } // end getEndVertex
 52:       
 53:       protected double getWeight()
 54:       {
 55:          return weight; 
 56:       } // end getWeight
 57:    } // end Edge
 58: } // end Vertex