Problem Solving with C++ (9th Edition)
Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
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
Assignment 05 PART 1 Queues - Note Part 1 is a separate deliverable: Write a class with a main method that uses a priority queue to store a list of prioritized chores. This is all the information that is provided. The rest is up to you. You may decide how to store your chores and how to store your priorities. YOU MUST WRITE your own Queue class – do not use the Java Library, Queue Class.
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