-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueuelinklist.py
53 lines (45 loc) · 1.14 KB
/
queuelinklist.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
44
45
46
47
48
49
50
51
52
53
class Node:
def __init__(self,data=None,nxt=None):
self.data=data;
self.nxt=nxt;
class Queue:
def __init__(self):
self.head=Node()
self.front=None
self.rear=None
self.size=0
def enque(self,x):
temp=Node(x,None)
if(self.head.nxt==None):
self.head.nxt=temp
self.front=temp
self.rear=temp
else:
self.rear.nxt=temp
self.rear=temp
self.size+=1
def deque(self):
if (self.head.nxt==None):
print ("Empty Queue")
else:
k=self.head.nxt
self.front=self.head.nxt.nxt
self.head.nxt=self.head.nxt.nxt
self.size=self.size-1
return k
self.size=self.size-1
def qprint(self):
while(self.head.nxt!=None):
print(self.head.nxt.data)
self.head.nxt=self.head.nxt.nxt
def main():
q=Queue()
q.enque(2)
q.enque(3)
q.enque(5)
print("size is:")
print(q.size)
print("elements are:")
q.qprint()
if __name__ == '__main__':
main()