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’);
int indexForU = graph.get Index(‘U’);
int indexForV = graph.get Index(‘V’);
System.out.println(“indexForU is ” + indexForU);
System.out.println(“indexForV is ” + indexForV);
graph.addEdge(indexForU, indexForV, 2.5);
System.out.println(“Degree of U is ” +
graph.getDegree(indexForU));
System.out.println(“Degree of V is ” +
graph.getDegree(indexForV));
System.out.println(“Weight of UV is ” +
graph.getWeight(indexForU, index0fV));
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 29 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Problem Solving with C++ (10th Edition)
Programming in C
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Starting Out With Visual Basic (7th Edition)
Digital Fundamentals (11th Edition)
C Programming Language
- Course: Data Structure and Algorithims Language: Java Kindly make the program in 2 hours. Task is well explained. You have to make the proogram properly in Java and attach output screen with program: Restriction: Prototype cannot be change you have to make program by using given prototype. TAsk: classBSTNode { Node left; Node right; int data; publicBSTNode(int _data);// assign data to_data and assign left and right node to null } class BST { BSTNoderoot; public BST();// assign root to null void insert(int data);// this function insert the data in tree which maintain property of BST boolean Search(int key); this function search the data in bst and return true if key is found else return false public void EvenPrint(Node n)// this function only print the data which are even, make this function resursive public void OddPrint(Node n)// this function only print the data which are odd, make this function resursive public void PrimePrint(Node n)// this function only…arrow_forwardA/ find code optimization method to this code and then find type to this code 1- For(i=1;iarrow_forwardExplain the following code : public static void printLeafNodes(TreeNode node) { // base case if (node == null) { return; } if (node.left == null && node.right == null) { System.out.printf("%d ", node.value); } printLeafNodes(node.left); printLeafNodes(node.right); }arrow_forwardDraw the control flow graph of the code.arrow_forwardUsing the graph in the question: Write Java code to create an Adjacency Matrix M to represent the graph. Write Java code to create an Adjacency List L to represent the graph.arrow_forwardUML Diagrams: Course -courseName: String -students: Student [] -numberOfStudents: int +Course(courseName : String) +getCourseName() : String +addStudent (student : Student) : void +addStudent (studentName: String): void +dropStudent(studentId: int ) : void +getStudents() : Student [] +getNumberOfStudents() : int a. How many constructors does Course have? b. How many methods that are void? c. How many methods that return a value? d. What is the parameter to the method dropStudent?arrow_forwardWrite a program in c++ which should create a weighted graph of the values entered by the user andthen write functions that perform the following: 1. Depth first search of source and destination vertex2. Breadth first search of source and destination vertex3. Shortest path search of source and all destination vertices (Dijkstra’s algorithm)4. Shortest path search of source and destination vertex (Dijkstra’s algorithm) The program should present a menu of the options and should run until the user opts to quit.arrow_forwardclass Node{int data;Node next;public Node (int d) {this(d,null);} public Node (int d,Node n) {data=d;next=n;}}public class List {private Node head; public List() {head=null;}public void addBegenning(int d) {Node n= new Node(d);if (head==null) {head=n;}else {n.next=head;head=n;}}public void addEnd(int d) {if (head==null) {head=new Node(d);}else {Node tmp=head;while(tmp.next!=null)tmp=tmp.next;tmp.next=new Node(d);} }public String toString() {Node tmp=head;String ans="";while(tmp!=null) {ans+=tmp.data+"-->";tmp=tmp.next;}return ans;}public void deleteBegging() {if (head!=null) {head=head.next;}}public void deleteEnd() {Node tmp=head;Node prev= null;while(tmp.next!=null) {prev=tmp;tmp=tmp.next;}prev.next=null;} public boolean contains(int d) {Node tmp=head;while (tmp!=null) {if (tmp.data==d)return true;tmp=tmp.next;}return false; }public void Remove(int d) {//if the d not exsist Node tmp=head;Node prev= null;while (tmp.data!=d) {// tmp!=null…arrow_forwardC++ A program applying the topics involved in data structures (linked list, graph, array etc.) 1. User will be asked to login/signup 2. User will choose for the nearest restaurant (undirected graph?) 3. User will add to cart (from the menu list of the restaurant) 4. User will be asked for order confirmation and mode of payment (cash on delivery, card??) note: new users will have a discount 5. Invoice Using Dev c++arrow_forwardAssume the following definition public class Node { private double price; private int range; // constructor ... not important public double getPrice () { return price; } } Determine what the following method will return. public boolean test (Node [] list, int n) { int i = 1; for (; i list[i-1].getPrice ()) break; if (i == n) return true; return false; } The array is sorted by price in increasing order It will create a runtime error It will create a syntax error The array is sorted by price in decreasing orderarrow_forwardHi i need an implementation on the LinkListDriver and the LinkListOrdered for this output : Enter your choice: 1 Enter element: Mary List Menu Selections 1. add element 2_remove element 3.head element 4. display 5.Exit Enter your choice: 3 Element @ head: Mary List Menu Selections 1-add element 2-remove element 3_head element 4.display 5-Exit Enter your choice: 4 1. Mary List Menu Selections 1. add element 2. remove element 3.head element 4. display 5. Exit Enter your choice: LinkedListDriver package jsjf; import java.util.LinkedList; import java.util.Scanner; public class LinkedListDriver { public static void main(String [] args) { Scanner input = new Scanner(System.in); LinkedList list = new LinkedList(); int menu = 0; do { System.out.println("\nList menu selection\n1.Add element\n2.Remove element\n3.Head\n4.Display\n5.Exit"); System.out.println();…arrow_forwardclass Queue { private static int front, rear, capacity; private static int queue[]; Queue(int c) { front = rear = 0; capacity = c; queue = new int[capacity]; } static void queueEnqueue(int data) { if (capacity == rear) { System.out.printf("\nQueue is full\n"); return; } else { queue[rear] = data; rear++; } return; } static void queueDequeue() { if (front == rear) { System.out.printf("\nQueue is empty\n"); return; } else { for (int i = 0; i < rear - 1; i++) { queue[i] = queue[i + 1]; } if (rear < capacity) queue[rear] = 0; rear--; } return; } static void queueDisplay() { int i; if (front == rear) { System.out.printf("\nQueue is Empty\n"); return; } for (i = front; i < rear; i++) { System.out.printf(" %d <-- ", queue[i]); } return; } static void queueFront() { if (front == rear) { System.out.printf("\nQueue is Empty\n"); return; } System.out.printf("\nFront Element is: %d", queue[front]);…arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education