@@ -16,34 +16,31 @@ def dequeue(self):
16
16
17
17
#Get the front item of the Queue
18
18
def front (self ):
19
- return self .arr [0 ]
19
+ return None if self . isEmpty () else self .arr [0 ]
20
20
21
21
#Get the last item from the queue
22
22
def rear (self ):
23
- return self .arr [- 1 ]
23
+ return None if self . isEmpty () else self .arr [- 1 ]
24
24
25
- #To display the whole Stack
26
- def display (self ):
27
- print (self .arr )
28
25
29
26
x = Queue () #Creating an object of queue class
30
- x . display ( )
27
+ print ( x . arr )
31
28
print ('Enquing 1 into queue' )
32
29
x .enqueue ('1' )
33
- x . display ( )
30
+ print ( x . arr )
34
31
print ('Enquing 1 into queue' )
35
32
x .enqueue ('2' )
36
- x . display ( )
33
+ print ( x . arr )
37
34
print ('Peeking the front item of the queue' )
38
35
print (x .front ())
39
36
print ('Peeking the rear item of the queue' )
40
37
print (x .rear ())
41
38
print ('Dequing an item from the queue' )
42
39
print (x .dequeue ())
43
- x . display ( )
40
+ print ( x . arr )
44
41
print ('Dequing an item from the queue' )
45
42
print (x .dequeue ())
46
- x . display ( )
43
+ print ( x . arr )
47
44
print ('Checking if the queue is empty' )
48
45
print (x .isEmpty ())
49
46
print ('Dequing an item from the queue even though the queue is empty' )
0 commit comments