blob: ff36bfd5294ee69018b2d76193f10743934e18f6 (
plain)
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
54
55
|
import time
import math
def is_empty(queue):
if not queue:
print("Queue is empty")
else:
print("Queue is not empty")
def insert_with_priority(queue):
print('Enter the priority of the element you want to insert')
priority = int(input())
timestamp = time.time()
queue.append([priority, timestamp])
return queue
def pull_highest_prority_element(queue):
queue.remove(max(queue))
return queue
available_choices = [1, 2, 3, 4]
queue = []
while 1:
print('\n\n')
print('================================')
print('Current status of queue')
if not queue:
print(queue)
else:
for i in range(0, len(queue)):
print(queue[i][0])
print('1. Check if queue is empty')
print('2. Insert with priority')
print('3. Pull highest priority element')
print('4. Exit')
print('Enter the number of your choice')
choice = int(input())
while (choice not in available_choices):
print('Please enter a valid choice')
choice = int(input())
if (choice == 1):
is_empty(queue)
if (choice == 2):
queue = insert_with_priority(queue)
if (choice == 3):
queue = pull_highest_prority_element(queue)
if (choice == 4):
break
|