Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
Dijkstra algorithm implementation More...
#include <cassert>
#include <climits>
#include <iostream>
#include <vector>
Classes | |
class | greedy_algorithms::dijkstra::Graph |
Wrapper class for storing a graph. More... | |
Namespaces | |
namespace | greedy_algorithms |
for std::vector | |
Functions | |
int | greedy_algorithms::dijkstra::minimum_distance (std::vector< int > mdist, std::vector< bool > vset, int V) |
Utility function that finds the vertex with the minimum distance in mdist . | |
void | greedy_algorithms::dijkstra::print (std::vector< int > dist, int V) |
Utility function to print the distances to vertices. | |
void | greedy_algorithms::dijkstra::dijkstra (Graph graph, int src) |
The main function that finds the shortest path from a given source to all other vertices using Dijkstra's Algorithm. | |
static void | tests () |
Self-test implementations. | |
int | main () |
Main function. | |
Dijkstra algorithm implementation
Quote from Wikipedia.
Dijkstra's algorithm is an algorithm for finding the shortest paths between nodes in a weighted graph, which may represent, for example, road networks. It was conceived by computer scientist Edsger W. Dijkstra in 1956 and published three years later.
void greedy_algorithms::dijkstra::dijkstra | ( | Graph | graph, |
int | src ) |
The main function that finds the shortest path from a given source to all other vertices using Dijkstra's Algorithm.
graph | the graph to be processed |
src | the source of the given vertex |
int main | ( | void | ) |
int greedy_algorithms::dijkstra::minimum_distance | ( | std::vector< int > | mdist, |
std::vector< bool > | vset, | ||
int | V ) |
Utility function that finds the vertex with the minimum distance in mdist
.
mdist | array of distances to each vertex |
vset | array indicating inclusion in the shortest path tree |
V | the number of vertices in the graph |
void greedy_algorithms::dijkstra::print | ( | std::vector< int > | dist, |
int | V ) |
Utility function to print the distances to vertices.
This function prints the distances to each vertex in a tabular format. If the distance is equal to INT_MAX, it is displayed as "INF".
dist | An array representing the distances to each vertex. |
V | The number of vertices in the graph. |
|
static |
Self-test implementations.