Function graph_algorithms::dijkstras
source · [−]pub fn dijkstras()Expand description
Performs Dijkstra’s algorithm on a given directed graph represented as an adjacency list. Prints a vector of vectors, where each inner vector contains the nodes of dijkstras in sorted order.
Inputs
-
vertices- Total number of vertices in the graph. -
source- A vertex in the graph from which min weight to be calculated to all other vertices in the graph. -
edges- Total Number of edges in the graph. -
Source(s) Destination(d) Weight(w)- Source, Destination and Weight for each edge in the graph.
Output
Prints minimum weight from the source vertex to all vertices in the graph.
Sample Input
Please Enter Number of Vertices in the Graph : 5
Please Enter Source Vertex : 0
Please Enter Number of edges in the graph : 3
Please Enter Edge 1 values
Source : 0
Destination : 1
Weight(>0) : 10
Please Enter Edge 2 values
Source : 0
Destination : 2
Weight(>0) : 5
Please Enter Edge 3 values
Source : 3
Destination : 4
Weight(>0) : 4
Sample Output
Distance from vertex 0 to vertex 0 is 0
Distance from vertex 0 to vertex 1 is 10
Distance from vertex 0 to vertex 2 is 5
Distance from vertex 0 to vertex 3 is 2147483647
Distance from vertex 0 to vertex 4 is 2147483647