projects / schoolwork / dijkstra


dijkstra


This program is written in C++ and is meant as an implementation for Dijkstra's algorithm, which is used to find the shortest path of points between two destinations. A starting (starting_city) and endpoint (ending_city) are given via a file, along with various stops along the way. The program will determine the shortest path between the starting and ending points using the distances between the intermediate destinations.

The program works by reading in sets of data points, 2 at a time, and the distance between them. These values are added to the adjacency list. There are two arrays, prev_verts and distance, whose indices are the different points from the data file. They keep track of the shortest point that led to that point, and the shortest distance to that point, respectively.

The list is iterated through, with the points being added back into a queue if their 'best' distance was changed (if the path to that node was found to be obsolete and a better path was found). Once the best path is found, the shortest distance is output along with the path it took to get from the starting point to the ending point.



code


Loading...