Created
May 22, 2021 13:48
-
-
Save Park-Developer/30aea384aed9234842b59c7c58fca0d6 to your computer and use it in GitHub Desktop.
Queue Using List
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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