Answered step by step
Verified Expert Solution
Question
1 Approved Answer
( 1 0 points ) Write a PriorityQueueList class that implements a priority queue using a singly linked list that is always kept sorted. Your
points Write a PriorityQueueList class that implements a priority queue using a
singly linked list that is always kept sorted. Your class needs the following components:
A constructor that initializes the list and a size instance attribute
A method that shows the list elements from head to tail
An enqueue method that traverses the list until finding the correct insertion point,
then inserts the new element into the list
A dequeue method that removes and returns the element at the head of the list. If
the list is empty, this method returns None.
A peek method that returns without removing the element at the head of the list.
If the list is empty, this method returns None.
You can reuse the Node class that we defined earlier for a singly linked list.
points Below the PriorityQueueList class definition in priorityqueuelist.py
write a program that does the following:
First, test your PriorityQueueList class.
Enqueue some elements into a PriorityQueueList object, then repeatedly peek and
dequeue until the queue becomes empty.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started