-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path32-Queue by using List DataType.py
43 lines (43 loc) · 1.17 KB
/
32-Queue by using List DataType.py
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
# Implement a Stack and Queue Using a List Data Type
# Queue(First In First Out) Operation in Python:
List = []
while True:
choice = int(input(
'''
Enter 1 for Push(Append) Element
Enter 2 for Pop Element
Enter 3 for Front(First) Element
Enter 4 for Rear(End) Element
Enter 5 for Display Queue
Enter 6 for Exit
'''
))
if choice == 1:
n = input("Enter the value: ")
List.append(n)
print(List)
elif choice == 2:
if len(List) == 0:
print("Empty Queue!")
else:
del List[0]
print(List)
elif choice == 3:
if len(List) == 0:
print("Empty Queue!")
else:
print("First Queue Element: ", List[0])
elif choice == 4:
if len(List) == 0:
print("Empty Queue!")
else:
print("Last Queue Element: ", List[-1])
elif choice == 5:
if len(List) == 0:
print("Empty Queue!")
else:
print("Display Queue: ", List)
elif choice == 6:
break
else:
print("Invalid Operation!")