-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp.py
More file actions
53 lines (40 loc) · 1.33 KB
/
temp.py
File metadata and controls
53 lines (40 loc) · 1.33 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
49
50
51
52
53
class Queue(object):
def __init__(self, size):
self.queue = list()
self.size = size
def enqueue(self, item):
'''This function adds an item to the rear end of the queue '''
if (self.isFull() != True):
self.queue.append(item)
else:
print('Queue is Full!')
def dequeue(self):
''' This function removes an item from the front end of the queue '''
if (self.isEmpty() == False):
return self.queue.pop(0)
else:
print('Queue is Empty!')
def isEmpty(self):
''' This function checks if the queue is empty '''
return self.queue == []
def isFull(self):
''' This function checks if the queue is full '''
return len(self.queue) == self.size
def peek(self):
''' This function helps to see the first element at the front end of the queue '''
if (self.isEmpty() != True):
return self.queue[0]
else:
print('Queue is Empty!')
if __name__ == '__main__':
myQueue = Queue(10)
myQueue.enqueue(4)
myQueue.enqueue(5)
myQueue.enqueue(6)
print(myQueue)
myQueue.enqueue(1)
myQueue.enqueue(2)
myQueue.enqueue(3)
print(myQueue)
myQueue.dequeue()
print(myQueue)