-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue_LL.py
More file actions
75 lines (56 loc) · 1.64 KB
/
Queue_LL.py
File metadata and controls
75 lines (56 loc) · 1.64 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class node:
def __init__(self,data):
self.data=data
self.next=None
class Queue:
def __init__(self):
self.head=None
self.tail=None
self.c=0
def enqueue(self,data):
newnode=node(data)
self.c+=1
if self.head==None:
self.head=newnode
self.tail=newnode
else:
self.tail.next=newnode
self.tail=newnode
def dequeue(self):
a=self.head.data
self.head=self.head.next
self.c-=1
return a
def n(self): #count number of elements
return self.c
def display(self):
start=self.head
while(start!=None):
print(start.data,end=" ")
start=start.next
print("\n")
def peek(self):
return self.head.data
def isempty(self):
return self.head==None
if __name__=='__main__':
s=Queue()
while(True):
op=input("ENTER OPERATION NAME IN UPPERCASE. PRESS 0 TO STOP: ")
if op=="ENQUEUE":
n=int(input("ENTER UR DATA: "))
s.enqueue(n)
elif op=="DEQUEUE":
print(s.dequeue())
elif op=="DISPLAY":
s.display()
elif op=="PEEK":
print(s.peek())
elif op=="COUNT":
print(s.n())
elif op=="ISEMPTY":
print(s.isempty())
elif op=="0":
break
else:
print("IMPROPER OPERATION REQUEST!!!!")