Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
Question
Book Icon
Chapter 29.3, Problem 29.3.2CP
Program Plan Intro

Given Code:

/* Add weighted edges in a new Array List by importing from Priority Queue class*/

List<PriorityQueue<WeightedEdge>> queues = new ArrayList<>();

/* using queue.get() method add new weighted edges with their respective weights*/

queues.get(0).offer(new WeightedEdge(0, 2, 3.5));

queues.get(0).offer(new WeightedEdge(0, 6, 6.5));

queues.get(0).offer(new WeightedEdge(0, 7, 1.5));

queues.get(1).offer(new WeightedEdge(1, 0, 3.5));

queues.get(1).offer(new WeightedEdge(1, 5, 8.5));queues.get(1).offer(new WeightedEdge(1, 8, 19.5));

/* using peek() method of queue compare the weighted edge with index 0 with  index 1*/

System.out.println(queues.get(0).peek().compareTo(queues.get(1).peek()));

Blurred answer
Students have asked these similar questions
Trying this again since part of my question keeps disappearing  Given main() in the ShoppingList class, define an insertAtEnd() method in the ItemNode class that adds an element to the end of a linked list. DO NOT print the dummy head node. Ex. if the input is: 4 Kale Lettuce Carrots Peanuts where 4 is the number of items to be inserted; Kale, Lettuce, Carrots, Peanuts are the names of the items to be added at the end of the list. The output is: Kale Lettuce Carrots Peanuts public class ItemNode {   private String item;   private ItemNode nextNodeRef; // Reference to the next node                                            public ItemNode() {      item = "";      nextNodeRef = null;   }    // Constructor                                                                                        public ItemNode(String itemInit) {      this.item = itemInit;      this.nextNodeRef = null;   }    // Constructor…
Given two linked lists sorted in increasing order, write a method intersection( ) to return a new list representing the intersection of the two lists. The new list should be made with its own memory — the original lists should not be changed. Example: if list1 contains {3,4,7,9,11} and list contains {2,3,8,9,12,15} so the intersection list3 is {3,9}.
We can declare a new array and copy the items of the old queue to new and by this, it will extend the size of the queue.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education