diff options
| author | root <root@turin.home> | 2022-01-16 14:19:54 +0000 |
|---|---|---|
| committer | root <root@turin.home> | 2022-01-16 14:19:54 +0000 |
| commit | d768da05fb2e52f291ec7e6e11f7435e668548a9 (patch) | |
| tree | b8513fb37f351eeb9e0e14a6b70268c114e159e6 /circular_queue.py | |
| parent | d7d89d19c2e795cbeb1f1b9136a9118aeacfb720 (diff) | |
Fix error which removes all elements from queue
Diffstat (limited to 'circular_queue.py')
| -rw-r--r-- | circular_queue.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/circular_queue.py b/circular_queue.py index 44954bd..6b36748 100644 --- a/circular_queue.py +++ b/circular_queue.py @@ -11,11 +11,13 @@ class circular_queue: self.pointer += 1 if self.pointer >= self.size: self.pointer = 0 - def average(self): - queue = self.queue - while None in queue: - queue.remove(None) - if len(queue) == 0: + value = 0 + length = 0 + for i in self.queue: + if i != None: + value += i + length += 1 + if length == 0: return 0 - return sum(queue) / len(queue) + return value / length |
