Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 17, Problem 6PP
Program Plan Intro
Priority queue
Program plan:
- Define a file “Priority.h” to declare operation and functions.
- Include the directives for header file.
- Declare a “PriorityQueue” template class.
- Define a template class named “Node”.
- Inside the access specifier “public”, define a constructor of class “Node”.
- Declare a friend class “PriorityQueue”.
- Inside the access specifier “private”, create an object for template.
- Declare an integer variable “priority” and create a pointer variable “*next”.
- Define a template class named “PriorityQueue”.
- Inside the access specifier “public”, Declare a constructor of class “PriorityQueue”.
- Declare the “add()” function to add items in the queue.
- Declare the “remove()” function to remove items from the queue.
- Declare the “isEmpty()” Boolean function to return the status of queue.
- Inside the access specifier “public”, Declare a constructor of class “PriorityQueue”.
- Define a file “main().cpp” to call functions from “Priority.h” and perform all computations.
- Define a constructor of class “PriorityQueue()” to assign “null” to “head” of the queue.
- Define “add()” function to add new node onto the front of the queue.
- Define “remove()” function to remove the smallest priority from the queue.
- Define “isEmpty()” function to return “true” or “false” if the queue is empty.
- Define a “main()” function.
- Create an object for class “PriorityQueue”.
- Add and remove some items in the queue and print the result.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Tour.java
Create a Tour data type that represents the sequence of points visited in a TSP tour. Represent the
tour as a circular linked list of nodes, one for each point in the tour. Each Node contains two
references: one to the associated Point and the other to the next Node in the tour. Each
constructor must take constant time. All instance methods must take time linear (or better) in the
number of points currently in the tour.
To represent a node, within Tour.java, define a nested class Node:
private class Node {
private Point p;
private Node next;
}
Your Tour data type must implement the following API. You must not add public methods to the
API; however, you may add private instance variables or methods (which are only accessible in the
class in which they are declared).
public class Tour
// Creates an empty tour.
public Tour()
// Creates the 4-point tour a→b→c→d→a (for debugging).
public Tour(Point a, Point b, Point c, Point d)
// Returns the number of points in this tour.
public…
Java
Problem Description:
1. Suppose that we want to add a method to a class of queues that will splice two
queues together. This method adds to the end of a queue all items that are in a
second queue. The header of the method could be as follows:
public void splice (QueueInterface anotherQueue)
Write this method in such a way that it will work in any class that
implements QueueInterface.
Chapter 17 Solutions
Problem Solving with C++ (10th Edition)
Ch. 17.1 - Write a function template named maximum. The...Ch. 17.1 - Prob. 2STECh. 17.1 - Define or characterize the template facility for...Ch. 17.1 - Prob. 4STECh. 17.1 - Display 7.10 shows a function called search, which...Ch. 17.1 - Prob. 6STECh. 17.2 - Give the definition for the member function...Ch. 17.2 - Give the definition for the constructor with zero...Ch. 17.2 - Give the definition of a template class called...Ch. 17.2 - Is the following true or false? Friends are used...
Ch. 17 - Write a function template for a function that has...Ch. 17 - Prob. 2PCh. 17 - Prob. 3PCh. 17 - Redo Programming Project 3 in Chapter 7, but this...Ch. 17 - Display 17.3 gives a template function for sorting...Ch. 17 - (This project requires that you know what a stack...Ch. 17 - Prob. 6PPCh. 17 - Prob. 7PPCh. 17 - This project requires that you complete...
Knowledge Booster
Similar questions
- Java All classes must be named as shown in the above UML diagram except the concrete child classes. The ItemList is a singly-linked list with the following methods: • insert(index: int, item: Item) : boolean o Inserts the given item at the given index if an equal item is not already in the list. If the method is successful it returns true. If an equal item already exists in the list or the index is out of range, this method returns false. • add(item: Item): boolean o Adds the given item to the front of the list. Returns true if successful and false if an equal item is already in the list. • set(index: int, item: Item) : Item o Replaces the object in the list at the given index with this object. If the index is out of range or the given item is already in the list, the method returns null. If the operation is successful, the method returns the object that was replaced by this one. • delete(index: int) : Item o Deletes the object at the given index from the list. If the index is out of…arrow_forwardThis one in c++.arrow_forwardIn this task, a skip list data structure should be implemented. You can follow the followinginstructions:- Implement the class NodeSkipList with two components, namely key node and arrayof successors. You can also add a constructor, but you do not need to add anymethod.- In the class SkipList implement a constructor SkipList(long maxNodes). The parameter maxNodes determines the maximal number of nodes that can be added to askip list. Using this parameter we can determine the maximal height of a node, thatis, the maximal length of the array of successors. As the maximal height of a nodeit is usually taken the logarithm of the parameter. Further, it is useful to constructboth sentinels of maximal height.- In the class SkipList it is useful to write a method which simulates coin flip andreturns the number of all tosses until the first head comes up. This number representsthe height of a node to be inserted.- In the class SkipList implement the following methods:(i) insert, which accepts…arrow_forward
- C++ programming design a class to implement a sorted circular linked list. The usual operations on a circular list are:Initialize the list (to an empty state). Determine if the list is empty. Destroy the list. Print the list. Find the length of the list. Search the list for a given item. Insert an item in the list. Delete an item from the list. Copy the list. Write the definitions of the class circularLinkedList and its member functions (You may assume that the elements of the circular linked list are in ascending order). Also, write a program to test the operations of your circularLinkedList class. NOTE: The nodes for your list can be defined in either a struct or class. Each node shall store int values.arrow_forwardIn Javaarrow_forwardJavaarrow_forward
- Using c++ I would like to implement a queue as a class with a linked list. This queue Is used to help the class print job in displaying things like: a confirmation of the job request received and the status ( denied/accepted) along with the details such as a tracking number, position in the queue( if accepted), reason for denial (if denied), etc. These classes will be used in a menu-driven application that has the following options: request a print job ask for the job name; the name may have blank spaces and consist of alphanumeric characters only, must start with a letter display a confirmation of the job request received and the status ( denied/accepted) along with the details such as a tracking number, position in the queue( if accepted), reason for denial (if denied), etc execute a print job (remove from the queue ) display a confirmation along with the tracking number, the name of the print job, and the number of print jobs currently in the queue display number of print…arrow_forwardCan anyone please solve this question asap ? Thank yoyuIn this question, you are required to implement singly linked list and its concepts to solve the problems of a departmental store described in the scenario given below:A departmental store has a variety of products to sell. Each product type has a unique ID and price associated with it (for example soaps can have an ID of 1 and price of 50 etc.). A customer comes to the store and starts putting items in his/her shopping cart. Once all theitems have been placed in the shopping cart, the customer then proceeds to checkout but before that, he/she will sort (in ascending order of IDs) the shopping cart’s items and proceed to remove all the duplicate items from the shopping cart, that is if two soaps have been added to the cart, only 1 will be kept. At the checkout counter, he/she will then remove items from the cart by removing from the end of the shopping cart (linked list). A bill for that customer is then generated and printed.You…arrow_forwarddata structures in javaarrow_forward
- java method : Write a method called prioritizeQueue to give priority for vaccination for elderly persons. The method is to be in a class called VaccinationQueue and has two parameters q1 and q2 type ArrayQueue. The q1 and q2 data are of type Integer. Assume that initially q1 is not empty and q2 is empty. The method will insert from q1 those elements towards the beginning of the queue (front) q2 whose data is greater than or equal to 45 and will insert those elements whose data is less than 45 and greater than or equal to 18 towards the end (rear) of q2. Any data item less than 18 of q1 will not be inserted in q2. It returns the number of elements added to q2. Class ArrayQueue and all its methods including iterator are available for use. You can also create temporary queues. You are not allowed to use arrays or any other data structure. Example: Before method call: front rear q1: 14 25 50 70 35 45 19 10 21…arrow_forwardPart 3: Building a Point of Sales (POS) linked list data structure. In a POS system, a transaction is based on items purchased by the customer. The following is an example of a customer transaction receipt, where the prices shown in the receipt are GST inclusive. Write a linked list classes (one class for Node and another class for List), which store the items in the transaction. Test the classes by printing the items in the linked list and show the total price of the transaction. The following listing is the sample output for your reference: ============================== BC Items Price ============================== 10 Pagoda Gnut 110g 3.49 11 Hup Seng Cream Cracker 4.19 12 Yit Poh 2n1 Kopi-o 7.28 13 Zoelife SN & Seed 5.24 14 Gatsby S/FO Wet&Hard 16.99 15 GB W/G U/Hold 150g 6.49 ============================== Total (GST Incl.) 43.68…arrow_forwardA readinglist is a doubly linked list in which each element of the list is a book. So, you must make sure that Books are linked with the previous prev and next element. A readinglist is unsorted by default or sorted (according to title) in different context. Please pay attention to the task description below. Refer to the relevance classes for more detail information. Implement the add_book_sorted method of the ReadingList class. Assume the readinglist is sorted by title, the add_book_sorted method takes an argument new_book (a book object), it adds the new_book to the readinglist such that the readinglist remain sorted by title. For example, if the readinglist contain the following 3 books: Title: Artificial Intelligence Applications Author: Cassie Ng Published Year: 2000 Title: Python 3 Author: Jack Chan Published Year: 2016 Title: Zoo Author: Cassie Chun Published Year: 2000 If we add another book (titled "Chinese History"; author "Qin Yuan"; and published year 1989) to the…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning