Question: ( finish the algorithm ) / / Dijkstra ' s shortest path algorithm - generating a table that contains the shortest distance from start to

(finish the algorithm)//Dijkstra's shortest path algorithm - generating a table that contains the shortest distance from start to every other vertex and the predecessor of each vertex.
//g is a graph. We will pass the graph created in our client file.
//start is the start vertex.
void DijkstraShortestPath(const graph& g, int start)
{
/*
minHeap ????????; //Create a min heap of the data type, vertex.
*/
/*
?????????//Create a dynamic array pointed to by locator, which is declared globally above.
//locator is an array containing the location of each vertex in the heap
//locator[0] always tells the location/index of vertex 0 in the heap. If the locator looks like [3,0,1,2], vertex 0 is located at index 3 in the heap, veertex 1 is located at index 0(meaning vertex 1 has the minimum distance).
*/
/*
//The following for loop populates the min heap with all the vertices. Set curDist to 999 and predecessor to -1.
//e.g. vertex for vertext number 0 should like this [0,999,-1]
// vertex for vertext number 1 should like this [1,999,-1]
vertex ver; //temp vertext struct used for multiple purposes
for (int i =0; i <?????; i++)
{
//fill ver (declared above) with 3 values
//call minHeap::insert() to insert each vertex
}
*/
/*
?????????//You need to initialize the locator array. To start with, locator array should look like this [0,1,2,3,4,...] telling us vertex 0 is at index 0 in the heap, vertex 1 is at index 1
*/
/*
//fill ver (declared above) with start, 0 and -1. start vertex should have 0 for curDist and -1 for predecessor
//If start is 3, ver should look like [3,0,-1]
ver.vertexNum =?????
ver.curDist =????
ver.predecessor =????
//call minHeap::updateElem() to update the start vertex's info
??????????
//the updateElem() will update the info at index i (first parameter).
//updateElem() will fix the min heap based on curDist starting at i.
//Since this start vertex has 0 for curDist and the other vertices have 999 for curDist,
//this start vertex should come up to the top
*/
/*
//******** Follow Dijkstra's algorithm and complete the following ***********
//Use printHeapArrays() for debugging
//After Dijkstra's algorithm is finished, call showShortestDistance() above to show the path and distance from start and destination
//Don't forget to destroy the dynamic array you made for locator
*/
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!