-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathBasic_Queue_Implementation.py
More file actions
96 lines (47 loc) · 1.04 KB
/
Copy pathBasic_Queue_Implementation.py
File metadata and controls
96 lines (47 loc) · 1.04 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
# coding: utf-8
# In[6]:
'''Defining a class called Queue'''
class Queue:
def __init__(self):
self.items=[]
def is_empty(self):
return not bool(self.items)
def enque(self,item):
self.items.insert(0,item)
def dequeue(self):
return self.items.pop()
def qsize(self):
return len(self.items)
def disp(self):
return self.items
# In[7]:
'''calling the class through object'''
q = Queue()
# In[24]:
'''checking if the queue is empty'''
q.is_empty()
# In[25]:
q.enque(4)
# In[26]:
q.disp()
# In[22]:
q.enque('kiran')
# In[21]:
q.dequeue()
# In[27]:
q.qsize()
# In[42]:
'''Hot potato encoding'''
def Hpotato(names, num):
queue = []
for name in names:
queue.insert(0,name)
while len(queue)>1:
for i in range(num):
queue.insert(0,queue.pop())
print(queue)
queue.pop()
return queue.pop()
Hpotato(['surya','kiran','udaya','kumar','arya','rahul'],9)
# In[ ]: