Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
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
Given the interface of the Linked-List struct Node{     int data;     Node* next = nullptr; }; class LinkedList{ private:     Node* head;     Node* tail; public:     display_at(int pos) const;     ... };   Write a definition for a method display_at. The method takes as a parameter integer that indicates the node's position which data you need to display.  Example: list: 5 -> 8 -> 3 -> 10 display_at(1); // will display 5 display_at(4); // will display 10   void LinkedList::display_at(int pos) const{      // your code will go here  }
using namespace std; class SinglyLinkedListNode { // INSERT YOUR CODE HERE }; class SinglyLinkedList { public: SinglyLinkedListNode *head; SinglyLinkedListNode *tail; SinglyLinkedList() { this->head = nullptr; this->tail = nullptr; } voidinsert_node(intnode_data) { // INSERT YOUR CODE HERE } }; void free_singly_linked_list(SinglyLinkedListNode* node) { // INSERT YOUR CODE HERE } // Complete the has_cycle function below. /* * For your reference: * * SinglyLinkedListNode { * int data; * SinglyLinkedListNode* next; * }; * */ bool has_cycle(SinglyLinkedListNode* head) { SinglyLinkedListNode* temp = head; bool isCycle = false; while (temp != nullptr) { // INSERT YOUR CODE HERE } } int main() { // INSERT YOUR CODE HERE TO TEST YOUR CODE return0; }
Given the IntNode class, define the getCount() method in the CustomLinkedList class that returns the number of items in the list not including the head node. Ex: If the list contains: head -> 14 -> 19 -> 4 getCount(headObj) returns 3. Ex: If the list contains: head -> getCount(headObj) returns 0.   public class IntNode {   private int dataVal;         // Node data   private IntNode nextNodePtr; // Reference to the next node    // Default constructor   public IntNode() {      dataVal = 0;      nextNodePtr = null;   }    // Constructor   public IntNode(int dataInit) {      this.dataVal = dataInit;      this.nextNodePtr = null;   }    // Constructor   public IntNode(int dataInit, IntNode nextLoc) {      this.dataVal = dataInit;      this.nextNodePtr = nextLoc;   }    /* Insert node after this node.    Before: this -- next    After:  this -- node -- next    */   public void insertAfter(IntNode nodeLoc) {      IntNode tmpNext;       tmpNext = this.nextNodePtr;…
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