-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathHacktoberfest 4th PR
62 lines (57 loc) · 1.23 KB
/
Hacktoberfest 4th PR
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
56
57
58
59
60
61
62
#Queues
#Functions
front=rear=0
def empty(q):
if q==[]:
return True
else:
return False
def push(q,value):
global front,rear
print('Add:')
q.append(value)
if len(q)==1:
front=rear=0
else:
rear+=1
def pop(q):
global front,rear
print('Delete:')
if empty(q)==True:
print('Underflow!')
elif front==rear:
returnvalue=q[front]
front=rear=0
q.clear()
else:
returnvalue=q[front]
front+=1
return returnvalue
def show(q):
global front,rear
for i in range(front,rear+1):
print(q[i],end=' ')
#main
ch=0
q=[]
while True:
print('\n \t \t QUEUE MENU\n Press 0 to Exit\n Press 1 to Add\n Press 2 to Delete\n Press 3 to Show\n Enter Your Choice:')
ch=int(input())
if ch==0:
break
elif ch==1:
if len(q)==0:
n=int(input('Enter First Value:'))
else:
n=int(input('Enter Next Value:'))
push(q,n)
elif ch==2:
if len(q)==0:
print('No Value-Underflow!')
else:
delvalue=pop(q)
print('Deleted value:',delvalue)
elif ch==3:
show(q)
else:
print('Wrong Choice!')