We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b23c70c commit 76b9eddCopy full SHA for 76b9edd
ring_buffer/ring_buffer.py
@@ -1,9 +1,22 @@
1
class RingBuffer:
2
def __init__(self, capacity):
3
- pass
+ self.capacity = capacity
4
+ self.data = []
5
+ self.oldest = 0
6
7
def append(self, item):
8
+ if len(self.data) < self.capacity:
9
+ self.data.append(item)
10
+ else:
11
+ self.data.remove(self.data[self.oldest])
12
+ self.data.insert(self.oldest, item)
13
+ if self.oldest+1 < self.capacity:
14
+ self.oldest += 1
15
16
17
18
def get(self):
19
+ for i in self.data:
20
+ if self.data == None:
21
+ self.data.remove(self.data[i])
22
+ return(self.data)
0 commit comments