File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change 11class RingBuffer :
22 def __init__ (self , capacity ):
3- pass
3+ self .capacity = capacity
4+ self .storage = [None ] * capacity # place to store the data concat int
5+ self .current = 0 # len is a tracker
6+
7+ # ds cannot be larger than capacity
48
59 def append (self , item ):
6- pass
10+ # update len
11+ if len (self .storage ) < self .capacity : # storage has to be < capacity
12+ self .storage .append (item ) # add item to storage
13+ else :
14+ self .storage [self .current ] = item # will move to next index
15+ # if storage is > than capacity - start at 0(current)
16+ if self .current < len (self .storage ) - 1 :
17+ self .current += 1
18+ else :
19+ self .current = 0
720
821 def get (self ):
9- pass
22+ new_items = [] # create a new list
23+ for i in self .storage : # loop through the storage
24+ if i is not None :
25+ new_items .append (i )
26+ return new_items
You can’t perform that action at this time.
0 commit comments