Dijkstra’s Algorithm implementation in java
Dijkstra is an algorithm in data structures. It finds the shortest path from the source node to other nodes in a graph. One condition is it should have non- negative weight. Here, it comes the implementation in java. Program implementation: This program starts from including the built-in package java.util.*. A class is created with Node implementation. It includes two variables g_vertex,g_weight. The constructor initialises the variable. ‘compareTo()’ -it compares the two integer variable and returns the value. ‘dijkstra()’ – This function has following activities. First, graph length is identified. ‘dist’ - it is a array with finds the distance. ‘n_visited’ – it sets whether the node is visited or not. A priority queue is created. An array is filled with distance. The shortest path is found out and added to priority queue. The distance and vertex is displayed. ‘main(...