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 Program Consider a class Student that has an attribute age and a method getAge(): StudentList is a class representing a linkedlist of students. Write sumListAge_lterative......), a method that computes and returns the sum of the ages of all students in the list using the iterative way. Parameters of the method should be specified accordingly
You need to implement a class for Dequeue i.e. for double ended queue. In this queue, elements can be inserted and deleted from both the ends.   You don't need to double the capacity.   You need to implement the following functions -   1. constructor   You need to create the appropriate constructor. Size for the queue passed is 10.   2. insertFront -   This function takes an element as input and insert the element at the front of queue. Insert the element only if queue is not full. And if queue is full, print -1 and return.   3. insertRear -   This function takes an element as input and insert the element at the end of queue. Insert the element only if queue is not full. And if queue is full, print -1 and return.   4. deleteFront -   This function removes an element from the front of queue. Print -1 if queue is empty.   5. deleteRear -   This function removes an element from the end of queue. Print -1 if queue is empty.   6. getFront -   Returns the element…
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