Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Finish the implimentation of this graph class. Then use it to print out the Vertex Distance Path Use a directed graph. class Graph { private:

Finish the implimentation of this graph class. Then use it to print out the Vertex Distance Path

Use a directed graph.

class Graph

{

private:

//Graph data structure here or create another class to implement it

?? public:

void insertVertex(int vertex); //inserts new vertex in graph

void insertEdge(int from, int to, int weight); //inserts new edge in graph

bool isEdge(int from, int to); //returns true if there is an edge between the vertices from and to

int getWeight(int from, int to); //returns the weight of the edge between the vertices from and to

vector getAdjacent(int vertex); //return a vector of integers representing vertices adjacent to vertex

void printDijkstra(int source); //prints result of running Dijkstra's algorithm with source vertex

void printGraph(); //prints graph in a format sorted by ascending vertex and edge list

};

Must take in this input

Sample Input

10 1 1 1 2 1 3 1 4 2 1 2 3 2 2 3 7 2 2 4 5 2 3 4 15 2 4 1 4 6 1

Must produce this output

Sample Output

Vertex Distance Path 2 3 1-2 3 10 1-2-3 4 8 1-2-4

Here is the main that you will work with but do not alter the main only alter the class.

int main() { //DO NOT CHANGE THIS FUNCTION. CHANGE YOUR IMPLEMENTATION CODE TO MAKE IT WORK int noOfLines, operation, vertex, to, fro, weight,source,j; vector arr; int arrSize; Graphs_P3 g; cin>>noOfLines; for(int i=0;i>operation; switch(operation) { case 1: cin>>vertex; g.insertVertex(vertex); break; case 2: cin>>fro; cin>>to; cin>>weight; g.insertEdge(fro,to,weight); break; case 3: cin>>fro; cin>>to; cout<>fro; cin>>to; cout<>vertex; arr=g.getAdjacent(vertex); arrSize = arr.size(); j=0; while(j>source; g.printDijkstra(source); cout<<" "; break; } } }

C++ and please comment the code and use readable variables thanks.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Write short notes on Interviews.

Answered: 1 week ago

Question

Define induction and what are its objectives ?

Answered: 1 week ago

Question

Discuss the techniques of job analysis.

Answered: 1 week ago

Question

How do we do subnetting in IPv6?Explain with a suitable example.

Answered: 1 week ago

Question

LO1 Understand risk management and identify its components.

Answered: 1 week ago