// path.java // demonstrates shortest path with weighted, directed graphs // to run this program: C>java PathApp //////////////////////////////////////////////////////////////// class DistPar // distance and parent { // items stored in sPath array public int distance; // distance from start to this vertex public int parentVert; // current parent of this vertex // ------------------------------------------------------------- public DistPar(int pv, int d) // constructor { distance = d; parentVert = pv; } // ------------------------------------------------------------- } // end class DistPar /////////////////////////////////////////////////////////////// class Vertex { public char label; // label (e.g. 'A') public boolean isInTree; // ------------------------------------------------------------- public Vertex(char lab) // constructor { label = lab; isInTree = false; } // ------------------------------------------------------------- } // end class Vertex //////////////////////////////////////////////////////////////// class Graph { private final int MAX_VERTS = 20; private final int INFINITY = 1000000; private Vertex vertexList[]; // list of vertices private int adjMat[][]; // adjacency matrix private int nVerts; // current number of vertices private int nTree; // number of verts in tree private DistPar sPath[]; // array for shortest-path data private int currentVert; // current vertex private int startToCurrent; // distance to currentVert // ------------------------------------------------------------- public Graph() // constructor { vertexList = new Vertex[MAX_VERTS]; // adjacency matrix adjMat = new int[MAX_VERTS][MAX_VERTS]; nVerts = 0; nTree = 0; for(int j=0; j