Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

Pseudocode of Dijkstra’s Algorithm in C++

function dijkstra(G, S)
    for each vertex V in G
        dist[V] <- infinite
        prev[V] <- NULL
        If V != S, add V to Priority Queue Q
    dist[S] <- 0
    
    while Q IS NOT EMPTY
        U <- Extract MIN from Q
        for each unvisited neighbour V of U
            temperoryDist <- dist[U] + edgeWeight(U, V)
            if temperoryDist < dist[V]
                dist[V] <- temperoryDist
                prev[V] <- U
    return dist[], prev[]
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Pseudocode #Algorithm
ADD COMMENT
Topic
Name
1+6 =