src/com/michaelho/DynamicProgramming/DP3.java
/**
         * Calculate the shortest distance of two vertices.
         *
         * @param dist The distance array which is used to store shortest distance of src to other vertices.
         * @param sptSet The boolean array that indicates whether the vertex is processed.
         * @param V The vertex to calculate shortest distance.
         * */
Calculate the shortest distance of two vertices.
@param dist The distance array which is used to store shortest distance of src to other vertices.
@param sptSet The boolean array that indicates whether the vertex is processed.
@param V The vertex to calculate shortest distance.
Calculate the shortest distance of two vertices . @param dist The distance array which is used to store shortest distance of src to other vertices . @param sptSet The boolean array that indicates whether the vertex is processed . @param V The vertex to calculate shortest distance .
int minDistance(int[] dist, boolean[] sptSet, int V) {
            int min = Integer.MAX_VALUE, minIndex = -1;
            for (int v = 0; v < V; v++) {
                if (!sptSet[v] && dist[v] <= min) {
                    min = dist[v];
                    minIndex = v;
                }
            }
            return minIndex;
        }
int minDistance ( int [ ] dist , boolean [ ] sptSet , int V ) { int min = Integer . MAX_VALUE , minIndex = - 1 ; for ( int v = 0 ; v < V ; v ++ ) { if ( ! sptSet [ v ] && dist [ v ] <= min ) { min = dist [ v ] ; minIndex = v ; } } return minIndex ; }
Calculate the shortest distance of two vertices.
Calculate the shortest distance of two vertices .
// Initialize min value