summaryrefslogtreecommitdiff
path: root/circular_queue.py
diff options
context:
space:
mode:
authorroot <root@turin.home>2022-01-16 13:40:19 +0000
committerroot <root@turin.home>2022-01-16 13:40:19 +0000
commitbefb917ec5cbcbb0aaae33c53e6c0b2c4b92afcf (patch)
treec2bcffbd5a831d376218f7b2e92cc4b382e0a43b /circular_queue.py
parent7104802fedc605cb386339733a6162e10da2aabd (diff)
Avoid naming conflict with queue library
Diffstat (limited to 'circular_queue.py')
-rw-r--r--circular_queue.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/circular_queue.py b/circular_queue.py
new file mode 100644
index 0000000..85516cf
--- /dev/null
+++ b/circular_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)