summaryrefslogtreecommitdiff
path: root/queue.py
diff options
context:
space:
mode:
authorroot <root@turin.home>2022-01-16 13:26:16 +0000
committerroot <root@turin.home>2022-01-16 13:26:16 +0000
commit4f95a0a75be6948a7eb36a8f5563301e740c8d32 (patch)
tree9feaac229deb79be4ad59623de1b68b971438ae4 /queue.py
parent0a13b53c5c3de8e884172a2c07c6c7fa3ae72215 (diff)
Implement circular queue
Diffstat (limited to 'queue.py')
-rw-r--r--queue.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/queue.py b/queue.py
new file mode 100644
index 0000000..85516cf
--- /dev/null
+++ b/queue.py
@@ -0,0 +1,19 @@
+class circular_queue:
+ def __init__(self,size):
+ self.size = size
+ self.queue = []
+ for i in range(self.size):
+ self.queue.append(None)
+ self.pointer = 0
+ def add(self, value):
+ self.queue[self.pointer] = value
+ self.pointer += 1
+ if self.pointer > 49:
+ self.pointer = 0
+ def average(self):
+ queue = self.queue
+ while None in queue:
+ queue.remove(None)
+ if len(queue) == 0:
+ return 0
+ return sum(queue) / len(queue)