Question: Below is a partial ` Graph ` class implementation. There is a method to add a vertex to the graph, ` addVertex ` , but
Below is a partial Graph class implementation. There is a method to add a vertex to the graph, addVertex but the code is missing functionality to add an edge or find a vertex. Modify the Graph class to include methods to add an edge and find a vertex by its value. Specifically:
addEdgekey key
This method takes the key values of two vertices in the graph and adds an edge between them. If one or both of the vertices dont exist in the graph, the method should print a message, "One or more vertices not found." and do not add any edges.
findVertexkey
This method takes the key value of the vertex to search for, and if its found in the graph, prints and returns the key values of its adjacent vertices.
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
