Source of 29.12.java


  1: public boolean connect(VertexInterface<T> endVertex, double edgeWeight)
  2: {
  3:    boolean result = false;
  4: 
  5:    if (!this.equals(endVertex))
  6:    {  // Vertices are distinct
  7:       Iterator<VertexInterface<T>> neighbors = getNeighborIterator();
  8:       boolean duplicateEdge = false;
  9: 
 10:       while (!duplicateEdge && neighbors.hasNext())
 11:       {
 12:          VertexInterface<T> nextNeighbor = neighbors.next();
 13:          if (endVertex.equals(nextNeighbor))
 14:             duplicateEdge = true;
 15:       } // end while
 16: 
 17:       if (!duplicateEdge)
 18:       {
 19:          edgeList.add(new Edge(endVertex, edgeWeight));
 20:          result = true;
 21:       } // end if
 22:    } // end if
 23: 
 24:    return result;
 25: } // end connect
 26: 
 27: public boolean connect(VertexInterface<T> endVertex)
 28: {
 29:    return connect(endVertex, 0);
 30: } // end connect
 31: // Version 4.0