-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueuesArrays.py
More file actions
48 lines (40 loc) · 1 KB
/
QueuesArrays.py
File metadata and controls
48 lines (40 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class QueuesArray:
def __init__(self):
self._data = []
def __len__(self):
return len(self._data)
def isempty(self):
return len(self._data) == 0
def enqueue(self, e):
self._data.append(e)
def dequeue(self):
if self.isempty():
print('Queue is empty')
return
return self._data.pop(0)
def first(self):
if self.isempty():
print('Queue is empty')
return
return self._data[0]
Q = QueuesArray()
Q.enqueue(5)
Q.enqueue(3)
print('Queue:',Q._data)
print('Queue Length:', len(Q))
ele = Q.dequeue()
print('Queue:',Q._data)
print('Queue Length:', len(Q))
print('Removed Element:',ele)
print('Is Queue Empty:',Q.isempty())
Q.enqueue(7)
print('Queue:',Q._data)
print('Queue Length:', len(Q))
Q.enqueue(12)
print('Queue:',Q._data)
print('Queue Length:', len(Q))
ele = Q.dequeue()
print('Queue:',Q._data)
print('Queue Length:', len(Q))
print('Removed Element:',ele)
print('First Element:',Q.first())