Listing 1

 /* (THE GREEDY LOOP)
  Obtaining a list of all links from the startVertex to all the other
  vertices. For the non-adjacent  vertices (virtual links - where a
  path is made up of multiple links) the initial value is INFINITY.
  The collection contains "n-1" OrientedLink instances, where "n" is
  the total number of vertices (candidates)*/
  OrientedLinkList linksFromStartVertex =
  orientedLinkList.getAllLinksFromPoint(startVertex,tempCandidates);
  while(linksFromStartVertex.getSize() > 0) {
   	/* Finding the shortest distance from the startVertex,
	considering all the points left in the linksfromStartVertex
	(this list reduces by one after every loop.)
	The secondStartVertex is the point with the shortest
	distance to the startVertex in the current loop (current
	content of the allLinksFromStartVertex list) */
	OrientedLink shortestLink = linksFromStartVertex.removeShortestLink();
  Point secondStartVertex = shortestLink.getEnd();
  tempCandidates.removePoint(secondStartVertex);
  long linkDistance = shortestLink.getLength();

   /* Calculating the distances from the secondStartVertex to
   all the other points that are still in the tempCandidates
   list (less startVertex and itself) */
   OrientedLinkList linksFromSecondStartVertex =
   orientedLinkList.getAllLinksFromPoint
   (secondStartVertex,tempCandidates);
   while(linksFromSecondStartVertex.getSize() > 0) {
   Point secondEndVertex = linksFromSecondStartVertex.
   removeShortestLink().getEnd();
   int secondEndVertexIndex = candidates.getPointIndex(secondEndVertex);

      /* If the total distance "dist" (startVertex ->
	     secondStartVertex -> current point (secondEndVertex)) is
		 smaller than the original distance (startVertex ->
		 current point) then "dist" is kept. Also the current point
		 gets saved into the pointMatrix */
		 long secondLinkDistance = orientedLinkList.
		 calculateLengthBetweenPoints
		 (secondStartVertex, secondEndVertex);
	 if(secondLinkDistance != PathConstants.INFINITY && 
          (linkDistance + secondLinkDistance <
		  distanceMatrix[i][secondEndVertexIndex])) {
		  distanceMatrix[i][secondEndVertexIndex] = 
		  linkDistance + secondLinkDistance;
		  pointMatrix[i][secondEndVertexIndex] = secondStartVertex;

	 /* modifying the length so that it will be picked up in the
	    correct order in the outer while loop */
	linksFromStartVertex.getLink(startVertex,secondEndVertex).
	setLength(linkDistance + secondLinkDistance);
  }
 }
}