Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f05b151

Browse files
Queue Implementation
1 parent 62ac680 commit f05b151

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

‎Data-Structures-and-Algorithms/Queue.py‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,31 @@ def dequeue(self):
1616

1717
#Get the front item of the Queue
1818
def front(self):
19-
return self.arr[0]
19+
return Noneifself.isEmpty() elseself.arr[0]
2020

2121
#Get the last item from the queue
2222
def rear(self):
23-
return self.arr[-1]
23+
return Noneifself.isEmpty() elseself.arr[-1]
2424

25-
#To display the whole Stack
26-
def display(self):
27-
print(self.arr)
2825

2926
x = Queue() #Creating an object of queue class
30-
x.display()
27+
print(x.arr)
3128
print('Enquing 1 into queue')
3229
x.enqueue('1')
33-
x.display()
30+
print(x.arr)
3431
print('Enquing 1 into queue')
3532
x.enqueue('2')
36-
x.display()
33+
print(x.arr)
3734
print('Peeking the front item of the queue')
3835
print(x.front())
3936
print('Peeking the rear item of the queue')
4037
print(x.rear())
4138
print('Dequing an item from the queue')
4239
print(x.dequeue())
43-
x.display()
40+
print(x.arr)
4441
print('Dequing an item from the queue')
4542
print(x.dequeue())
46-
x.display()
43+
print(x.arr)
4744
print('Checking if the queue is empty')
4845
print(x.isEmpty())
4946
print('Dequing an item from the queue even though the queue is empty')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /