From 9b8bfa0214bf8dd42b5d5c2be7cc9befa44527b1 Mon Sep 17 00:00:00 2001 From: VISHAL BHARTI <42848830+knightvishal@users.noreply.github.com> Date: Fri, 15 Oct 2021 13:53:16 +0530 Subject: [PATCH] =?UTF-8?q?Create=20Dijkstra=E2=80=99s=20Shortest=20path?= =?UTF-8?q?=20Algorithm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...stra\342\200\231s Shortest path Algorithm" | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 "Dijkstra\342\200\231s Shortest path Algorithm" diff --git "a/Dijkstra\342\200\231s Shortest path Algorithm" "b/Dijkstra\342\200\231s Shortest path Algorithm" new file mode 100644 index 0000000..9432e31 --- /dev/null +++ "b/Dijkstra\342\200\231s Shortest path Algorithm" @@ -0,0 +1,94 @@ +// A C++ program for Dijkstra's single source shortest path algorithm. +// The program is for adjacency matrix representation of the graph +#include +using namespace std; +#include + +// Number of vertices in the graph +#define V 9 + +// A utility function to find the vertex with minimum distance value, from +// the set of vertices not yet included in shortest path tree +int minDistance(int dist[], bool sptSet[]) +{ + + // Initialize min value + int min = INT_MAX, min_index; + + for (int v = 0; v < V; v++) + if (sptSet[v] == false && dist[v] <= min) + min = dist[v], min_index = v; + + return min_index; +} + +// A utility function to print the constructed distance array +void printSolution(int dist[]) +{ + cout <<"Vertex \t Distance from Source" << endl; + for (int i = 0; i < V; i++) + cout << i << " \t\t"<