Problem Solving with C++ Plus MyLab Programming with Pearson eText -- Access Card Package (10th Edition)
Problem Solving with C++ Plus MyLab Programming with Pearson eText -- Access Card Package (10th Edition)
10th Edition
ISBN: 9780134710747
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
The implementation for the priority queue in this chapter starts by modifying theHeap class so that the order of the elements can be determined by the programmer.Earlier the heap kept the highest value on the top of the container, but now it willbe altered to allow for either the highest or the lowest. The changes made to thisclass involve specifying another template parameter, which will be used for thecomparison operator. Altering the push() and pop() functions to make use of thecomparison operator instead of assuming that the largest value element will be ontop. use c++ to code.
Given the linked list data structure, implement a sub-class TSortedList that makes sure that elements are inserted and maintained in an ascending order in the list. So, given the input sequence {1,7,3,11,5}, when printing the list after inserting the last element it should print like 1, 3, 5, 7, 11. Note that with inheritance, you have to only care about the insertion situation as deletion should still be handled by the parent class.
Implements clone which duplicates a list. Pay attention, because if there are sublists, they must be duplicated as well. Understand the implementation of the following function, which recursively displays the ids of each node in a list  def show_ids(M, level=0):     k = M.first_node     while k is not None:         print(" "*2*level, id(k))         if (str(k.value.__class__.__name__) == str(M.__class__.__name__)):                         show_ids(k.value, level+1)         k = k.next        W=L2(Node(10, Node(L2(Node(14, Node(15, Node(L2(Node(16, Node(17))))))), Node(20, Node(30)))) )show_ids(W) Develop your solution as follows: - First copy the nodes of the current list (self) - Create a new list with the copied nodes - Loop through the nodes of the new list checking the value field - If this field is also a list (use isinstance as in the show_ids function) then it calls clone on that list and substitutes the value. Complete the code: def L4(*args,**kwargs):         class L4_class(L):…
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