Using an adjacency list of flight paths and iterative backtracking, this project will display the fastest or cheapest flight paths from a wanted origin to a wanted destination.
First, I created a Flight object that holds the origin, destination, cost, duration, and airline of the flight. Then, I parsed through the flight path input file and added flights to a flight adjacency list object. This adjacency list would hold all the possible flight paths between each city.
Next, I parse in the user input file of wanted flights. Using iterative backtracking and a self-made templated stack object, the algorithm searches through the entire adjacency list and stores all flight paths from a wanted origin to a wanted destination in another adjacency list.
An example of a flight data and wanted flights is shown below:
The algorithm then iterates through the saved flights adjacency list and records the total cost and time for each flight path - adding 43 minutes and $19 to the time and cost for each layover.
The algorithm then sorts the list by either time or cost (represented in the input file by a “T” or “C” respectively) and prints the 3 fastest or cheapest flight paths from the wanted origin to the wanted destination.
An example output using the inputs above is shown below:
Happy travels!