
Show the output of the following code:
public class Test {
public static void main(String[] args) {
WeightedGraph<Character> graph = new WeightedGraph<>();
graph.addVertex(‘U’);
graph.addVertex(‘V’);
graph.addVertex(‘X’);
int indexForU = graph.getIndex(‘U’);
int indexForV = graph.getIndex(‘V’);
int indexForX = graph.getIndex(‘X’);
System.out.println(“indexForU is ” + indexForU);
System.out.println(“indexForV is ” + indexForV);
System.out.println(“indexForX is ” + indexForV);
graph.addEdge(indexForU, indexForV, 3.5);
graph.addEdge(indexForV, indexForU, 3.5);
graph.addEdge(indexForU, indexForX, 2.1);
graph.addEdge(indexForX, indexForU, 2.1);
graph.addEdge(indexForV, indexForX, 3.1);
graph.addEdge(indexForX, indexForV, 3.1);
WeightedGraph<Character>.ShortestPathTree tree =
graph.getShortestPath(1);
graph.printWeightedEdges();
tree.printTree();
}
}

Want to see the full answer?
Check out a sample textbook solution
Chapter 29 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Electric Circuits. (11th Edition)
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Database Concepts (8th Edition)
Concepts Of Programming Languages
Modern Database Management
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageNew Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr




