Instructions:
SLLQueue (13 pts)
â— Using the three properties below, implement the
queue interface using the SLLNode class fromLab 2:
○ head_node → SLLNode object or None
○ tail_node → SLLNode object or None
○ size → int, keep track of queue size
â— Implement enqueue( ),dequeue( ), front( )
â— Use SLLNode methods:
get_item( ), set_item( ), get_next(), set_next( )
â— (5 pts) Inenqueue(item):
â—‹ Add new SLLNode (with item) after tail_node
â—‹ Update tail_node and size properties
â—‹ If first item, update head_node property too
â— (6 pts) In dequeue( ):
â—‹ If empty, raise Exception('Empty queue: cannot dequeue')
â—‹ Remove head node and return its item
â—‹ Remove any links from old head node
â—‹ Update head_node and size properties
â—‹ If queue becomes empty, reset head_node, tail_node
â— (2 pts) In front( ):
â—‹ If empty, raise Exception(Empty queue: no front')
○ Return head node’s item
Code:
class SLLQueue:
  def __init__(self):
     # NOTE: DO NOT EDIT THIS CODE
     # constructor: set propertieshead_node, tail_node, size
     self.head_node = None
     self.tail_node = None
     self.size = 0
  def __repr__(self):
     # NOTE: DO NOT EDIT THIS CODE
     # string representation of SLLQueueobject
     display = []
     node = self.head_node
     while node != None:
        display.append(str(node.get_item()))
        node =node.get_next()
     display = ', '.join(display)
     return 'front [' + display +']'
  def is_empty(self):
     # NOTE: DO NOT EDIT THIS CODE
     # check if queue is empty
     return self.size == 0
  def enqueue(self,item):
     # TODO: Write your codehere...
     # TODO: add new node (with item)after tail_node
     # TODO: update tail_node and sizeproperties
     # TODO: if this is the first nodeadded, update head_node too
    Â
     pass # TODO: remove this line
    Â
  def dequeue(self):
     # TODO: Write your codehere...
     # TODO: if empty, raiseException('Empty queue: cannot dequeue')
     # TODO: remove head_node and returnits item
     # TODO: remove any links from oldhead_node (Hint: set to None)
     # TODO: update head_node and sizeproperties
     # TODO: if queue becomes empty,reset head_node and tail_node
    Â
     pass # TODO: remove this line
  def front(self):
     # TODO: Write your codehere...
     # TODO: if empty, raiseException('Empty queue: no front')
     # TODO: return head_node's item
     pass # TODO: remove thisline