Question: from SLNode import SLNode class QueueException ( Exception ) : Custom exception to be used by Queue class DO NOT CHANGE THIS
from SLNode import SLNode
class QueueExceptionException:
Custom exception to be used by Queue class
DO NOT CHANGE THIS METHOD IN ANY WAY
pass
class Queue:
def initself:
Initialize new queue with head and tail nodes
DO NOT CHANGE THIS METHOD IN ANY WAY
self.head None
self.tail None
def strself:
Return content of queue in humanreadable form
DO NOT CHANGE THIS METHOD IN ANY WAY
out 'QUEUE
if not self.isempty:
node self.head
out out strnodevalue
node node.next
while node:
out out strnodevalue
node node.next
return out
def isemptyself bool:
Return True is the queue is empty, False otherwise
DO NOT CHANGE THIS METHOD IN ANY WAY
return self.head is None
def sizeself int:
Return number of elements currently in the queue
DO NOT CHANGE THIS METHOD IN ANY WAY
node self.head
length
while node:
length
node node.next
return length
#
def enqueueself value: object None:
TODO: Write this implementation
pass
def dequeueself object:
TODO: Write this implementation
pass
def frontself object:
TODO: Write this implementation
pass
# BASIC TESTING
if namemain:
print
# enqueue example
q Queue
printq
for value in :
qenqueuevalue
printq
print
# dequeue example
q Queue
for value in :
qenqueuevalue
printq
for i in range:
try:
printqdequeue
except Exception as e:
printNo elements in queue", typee
print
#front example
q Queue
printq
for value in ABCD:
try:
printqfront
except Exception as e:
printNo elements in queue", typee
qenqueuevalue
printq
class QueueExceptionException:
Custom exception to be used by Queue class.
DO NOT CHANGE THIS METHOD IN ANY WAY
pass
class Queue:
def initself None:
Initialize new queue based on Static Array.
DO NOT CHANGE THIS METHOD IN ANY WAY
self.sa StaticArray
self.front
self.back
self.currentsize
def strself str:
Override string method to provide more readable output.
DO NOT CHANGE THIS METHOD IN ANY WAY
size self.currentsize
out "QUEUE: strsize elements
frontindex self.front
for in rangesize :
out strselfsafrontindex
frontindex self.incrementfrontindex
if size :
out strselfsafrontindex
return out
def isemptyself bool:
Return True if the queue is empty, False otherwise.
DO NOT CHANGE THIS METHOD IN ANY WAY
return self.currentsize
def sizeself int:
Return number of elements currently in the queue.
DO NOT CHANGE THIS METHOD IN ANY WAY
return self.currentsize
def printunderlyingsaself None:
Print underlying StaticArray. Used for testing purposes.
DO NOT CHANGE THIS METHOD IN ANY WAY
printselfsa
def incrementself index: int int:
Move index to next position.
DO NOT CHANGE THIS METHOD IN ANY WAY
# employ wraparound if needed
index
if index self.salength:
index
return index
# #
def enqueueself value: object None:
TODO: Write this implementation
pass
def dequeueself object:
TODO: Write this implementation
pass
def frontself object:
TODO: Write this implementation
pass
TODO: Write this implementation
pass
def dequeueself object:
TODO: Write this implementation
pass
def frontself object:
TODO: Write this implementation
pass
# The method below is optional, but recommended, to implement. #
# You may alter it in any way you see fit. #
def doublequeueself None:
TODO: Write this implementation
pass
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
