Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
Question
Book Icon
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.
  • 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.

Blurred answer
Students 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.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning