Question: #include #include #include #include #include #include #include #include using namespace std; class Graph { private: int nodeCount; vector > > adjacencyList; vector prevNode; public: Graph
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
class Graph
private:
int nodeCount;
vector adjacencyList;
vector prevNode;
public:
Graphint nodeCount;
void insertEdgeint start, int end, int weight;
vector runDijkstraint source;
void printDistancesconst vector& distances;
;
Graph::Graphint nodeCount
thisnodeCount nodeCount;
adjacencyList.resizenodeCount;
prevNode.resizenodeCount;
void Graph::insertEdgeint start, int end, int weight
adjacencyListstartemplacebackend weight;
adjacencyListendemplacebackstart weight; Assuming undirected graph
vector Graph::runDijkstraint source
vector distancenodeCount INTMAX;
priorityqueue, vector greater pq;
distancesource;
pqemplace source;
while pqempty
int currentNode pqtopsecond;
int currentDistance pqtopfirst;
pqpop;
for const auto& neighbor : adjacencyListcurrentNode
int nextNode neighbor.first;
int edgeWeight neighbor.second;
if distancenextNode currentDistance edgeWeight
distancenextNode currentDistance edgeWeight;
prevNodenextNode currentNode;
pqemplacedistancenextNode nextNode;
return distance;
void Graph::printDistancesconst vector& distances
for int dist : distances
if dist INTMAX
cout "INF";
else
cout setw right dist;
cout ; Three spaces between each number
cout endl;
int main
ifstream inputFileinputtxt;
if inputFile.isopen
cerr "Error opening file." endl;
return ;
int nodeCount;
inputFile nodeCount;
Graph graphnodeCount;
int startNode, endNode, edgeWeight;
while inputFile startNode endNode edgeWeight
graph.insertEdgestartNode endNode, edgeWeight;
inputFile.close;
ofstream outputFileoutputtxt;
ofstream outputFileoutputtxt;
ofstream outputFileoutputtxt;
if outputFileisopenoutputFileisopenoutputFileisopen
cerr "Error opening output files." endl;
return ;
for int i ; i nodeCount; i
vector distances graph.runDijkstrai;
graph.printDistancesdistances;
outputFileclose;
outputFileclose;
outputFileclose;
return ;
with this code im getting this output:
when the formatting should be as such:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
