I am working on the implementation of Queue with a circularly linked list in python. Below is the pictorial representation of circularly LinkedList
I was able to implement most of the code except the dequeue routine. In dequeue routine, one has to keep track of the previous node reference as well as the next node reference with respect to current node. In double linked list, it's easy to implement. However, I have no idea how to implement this concept in single linked list.
class CircularQueue:
''' Queue implementation using a Circularly linked list for storage '''
class _Node:
__slots__ == '_element','_next'
def __init__(self,element,next):
self._element = element
self._next = next
def __init__(self):
'''Create an empty queue'''
self._current = None
self._size = 0
def __len__(self):
return self._size
def is_empty(self):
return self._size == 0
def enqueue(self,e):
node = self._Node(e,None)
if self.is_empty():
newest._next = newest
else:
curr_node = self._current._next
node._next = curr_node
self._current = node
self._size += 1
def dequeue(self):
if self.is_empty():
raise Empty('Stack is empty')
It would be more helpful if anyone can give me thoughts on how to move forward in dequeue routine.