Skip to content

Instantly share code, notes, and snippets.

@Park-Developer
Created May 22, 2021 13:48
Show Gist options
  • Save Park-Developer/30aea384aed9234842b59c7c58fca0d6 to your computer and use it in GitHub Desktop.
Save Park-Developer/30aea384aed9234842b59c7c58fca0d6 to your computer and use it in GitHub Desktop.
Queue Using List
class Node(object):
def __init__(self,value=None, pointer=None):
self.value = value
self.pointer=None
class LinkedQueue(object):
def __init__(self):
self.head=None
self.tail=None
self.count=0
def isEmpty(self):
return not bool(self.head)
def dequeue(self):
if self.head:
value=self.head.value
self.count -=1
return value
else:
print("Queue is Empty")
def enqueue(self,value):
node=Node(value)
if not self.head:
self.head=node
self.tail=node
else:
if self.tail:
self.tail.pointer=node
self.tail=node
self.count +=1
def size(self):
return self.count
def peek(self):
return self.head.value
def print(self):
node=self.head
while node:
print(node.value, end='')
node=node.pointer
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment