-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueue.py
More file actions
37 lines (31 loc) · 704 Bytes
/
queue.py
File metadata and controls
37 lines (31 loc) · 704 Bytes
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
#! /usr/local/bin/python
# -*- coding:utf-8 -*-
class queue():
def __init__(self,data=[]):
self.data=data
def queue_empty(self):
if len(self.data)==0:
return True
else:
return False
def enqueue(self,x):
self.data.append(x)
def dequeue(self):
if self.queue_empty():
print 'queue is empty'
else:
result=self.data[0]
self.data=self.data[1:]
return result
if __name__=='__main__':
q=queue()
q.enqueue(2)
print q.data
q.enqueue(3)
print q.data
q.dequeue()
print q.data
q.dequeue()
print q.data
q.dequeue()
print q.data