blob: 70db2838a09647813b6369eb2da51b59fe6b590d (
plain)
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
|
# Data Acquisition list based queue
class Queue:
"""A sample implementation of a First-In-First-Out
data structure."""
def __init__(self, length):
# Initializes with empty zeros
self.queue = [0] * length
self.length = length
def push(self,obj):
if len(self.queue) < self.length:
self.queue.append(obj)
else:
print "Queue full"
### To discard first in queue and append obj anyway ###
#self.queue.pop(0)
#self.queue.append(obj)
def pop(self):
try:
return (self.queue.pop(0))
except:
print "queue empty"
def size(self):
return len(self.queue)
def discard(self):
self.queue=[]
def flush(self):
self.return_queue = self.queue
self.queue = []
return(self.return_queue)
|