Path shortestPath(int startVertex) {    
    // Shortest distance known so far to reach vertex i
    /// from startVertex
    double [] distance = new double[current];
    
    // path[i] is the next vertex to use in the path from i
    // to startVertex (in the notes it may be refered as "parent")
    int [] path = new int[current];
    
    // Initially all vertices are unvisited.
    boolean [] visited = new boolean[current];
    
    for (int i=0; i < current; i++) {
      distance[i]=MaxDistance;
    }
    distance[startVertex]=0;
    
    // The next vertex to use to reach startVertex from StartVertex is
    // startVertex itself.
    path[startVertex]=startVertex;
    
    // Iterate while there are unvisited vertices
    while (true) {     
      // Get a vertex u that has not been visited and
      // that has minimum distance
      int u = -1;
      for (int i=0; i < current; i++) {
        if (!visited[i]) {
          // node has not been visited
          if (u<0 || distance[i] < distance[u]) {
            u=i;
          }
        }
      }
      
      if (u == -1) {
        // All nodes have been visited. We break from while
        break;
      }
      
      /// Set visited to true
      visited[u]=true;
      
      // Now recompute distances
      for (int z = 0; z < current; z++) {
        
        // For all adjacent vertices
        if (adjacent[u][z]) {
          // z is adjacent to u
          if (distance[z] > distance[u]+weight[u][z]) {
            // Update distance if path to z
            // through u is shorter
            distance[z] = distance[u]+weight[u][z];
            path[z]=u;
          }
        }
      }
    }
    
    // Return path and distance in Path class
    Path p = new Path();
    p.distance = distance;
    p.path = path;
    
    return p;
  }