Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the unweighted graph implementation provided. You will need to implemen

ID: 3855482 • Letter: C

Question

Complete the unweighted graph implementation provided. You will need to implement the various functions (constructor, addVertex, addEdge, print) and determine the data members. It is an unweighted graph; you can choose a directed/or undirected. This is c++ code.

- graph() constructs an empty graph

- addVertex() adds a vertex to your graph and returns its nodeid (an unsigned int). Starts at 0, then 1, etc.

- addEdge(to,from) adds an edge from nodeid to to nodeid from. If your graph is undirected, also adds the other edge.

- print() prints out the structure of the graph (node 0 is connected to nodes i, j, k and etc)

Explanation / Answer

#include #include #include using namespace std; class Vertex; class Edge { public: Edge(Vertex *org, Vertex *dest, int dist) { origin = org; destination = dest; distance = dist; } Vertex* getOrigin() {return origin;} Vertex* getDestination() {return destination;} int getDistance() {return distance;} private: Vertex* origin; Vertex* destination; int distance; }; class Vertex { public: Vertex(string id) { name = id; } void addEdge(Vertex *v, int dist) { Edge newEdge(this, v, dist); edges.push_back(newEdge); } void printEdges() { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote