Exercise

Implementing a queue for printer tasks

In the last video, you learned that queues can have multiple applications, such as managing the tasks for a printer.

In this exercise, you will implement a class called PrinterTasks(), which will represent a simplified queue for a printer. To do this, you will be provided with the Queue() class that includes the following methods:

  • enqueue(data): adds an element to the queue
  • dequeue(): removes an element from the queue
  • has_elements(): checks if the queue has elements. This is the code:
    def has_elements(self):
      return self.head != None

You will start coding the PrinterTasks() class with its add_document() and print_documents() methods. After that, you will simulate the execution of a program that uses the PrinterTasks() class.

Instructions 1/3

undefined XP
    1
    2
    3
  • Complete the add_document() function to add a document to the queue.
  • Complete the print_documents() function to iterate over the queue while it has elements, and remove each document in the queue.