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 QueueException(Exception):
"""
Custom exception to be used by Queue class
DO NOT CHANGE THIS METHOD IN ANY WAY
"""
pass
class Queue:
def __init__(self):
"""
Initialize new queue with head and tail nodes
DO NOT CHANGE THIS METHOD IN ANY WAY
"""
self._head = None
self._tail = None
def __str__(self):
"""
Return content of queue in human-readable form
DO NOT CHANGE THIS METHOD IN ANY WAY
"""
out = 'QUEUE ['
if not self.is_empty():
node = self._head
out = out + str(node.value)
node = node.next
while node:
out = out +'->'+ str(node.value)
node = node.next
return out +']'
def is_empty(self)-> bool:
"""
Return True is the queue is empty, False otherwise
DO NOT CHANGE THIS METHOD IN ANY WAY
"""
return self._head is None
def size(self)-> int:
"""
Return number of elements currently in the queue
DO NOT CHANGE THIS METHOD IN ANY WAY
"""
node = self._head
length =0
while node:
length +=1
node = node.next
return length
# -----------------------------------------------------------------------
def enqueue(self, value: object)-> None:
"""
TODO: Write this implementation
"""
pass
def dequeue(self)-> object:
"""
TODO: Write this implementation
"""
pass
def front(self)-> object:
"""
TODO: Write this implementation
"""
pass
# ------------------- BASIC TESTING -----------------------------------------
if __name__=="__main__":
print("
# enqueue example 1")
q = Queue()
print(q)
for value in [1,2,3,4,5]:
q.enqueue(value)
print(q)
print("
# dequeue example 1")
q = Queue()
for value in [1,2,3,4,5]:
q.enqueue(value)
print(q)
for i in range(6):
try:
print(q.dequeue())
except Exception as e:
print("No elements in queue", type(e))
print('
#front example 1')
q = Queue()
print(q)
for value in ['A','B','C','D']:
try:
print(q.front())
except Exception as e:
print("No elements in queue", type(e))
q.enqueue(value)
print(q)
class QueueException(Exception):
"""
Custom exception to be used by Queue class.
DO NOT CHANGE THIS METHOD IN ANY WAY
"""
pass
class Queue:
def __init__(self)-> None:
"""
Initialize new queue based on Static Array.
DO NOT CHANGE THIS METHOD IN ANY WAY
"""
self._sa = StaticArray(4)
self._front =0
self._back =-1
self._current_size =0
def __str__(self)-> str:
"""
Override string method to provide more readable output.
DO NOT CHANGE THIS METHOD IN ANY WAY
"""
size = self._current_size
out = "QUEUE: "+ str(size)+" element(s).["
front_index = self._front
for _ in range(size -1):
out += str(self._sa[front_index])+','
front_index = self._increment(front_index)
if size >0:
out += str(self._sa[front_index])
return out +']'
def is_empty(self)-> bool:
"""
Return True if the queue is empty, False otherwise.
DO NOT CHANGE THIS METHOD IN ANY WAY
"""
return self._current_size ==0
def size(self)-> int:
"""
Return number of elements currently in the queue.
DO NOT CHANGE THIS METHOD IN ANY WAY
"""
return self._current_size
def print_underlying_sa(self)-> None:
"""
Print underlying StaticArray. Used for testing purposes.
DO NOT CHANGE THIS METHOD IN ANY WAY
"""
print(self._sa)
def _increment(self, index: int)-> int:
"""
Move index to next position.
DO NOT CHANGE THIS METHOD IN ANY WAY
"""
# employ wraparound if needed
index +=1
if index == self._sa.length():
index =0
return index
# ---------------------------------------------------------------------- #
def enqueue(self, value: object)-> None:
"""
TODO: Write this implementation
"""
pass
def dequeue(self)-> object:
"""
TODO: Write this implementation
"""
pass
def front(self)-> object:
"""
TODO: Write this implementation
"""
pass
TODO: Write this implementation
"""
pass
def dequeue(self)-> object:
"""
TODO: Write this implementation
"""
pass
def front(self)-> 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 _double_queue(self)-> None:
"""
TODO: Write this implementation
"""
pass

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!