Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
buffer done still failing one test will come back
  • Loading branch information
bykristea committed Jan 11, 2020
commit 55261aaaf11290b2f5230d68d48563360e0426ed
17 changes: 16 additions & 1 deletion ring_buffer/ring_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,28 @@ def __init__(self, capacity):
self.storage = DoublyLinkedList()

def append(self, item):
pass
# checking to see if at capacity
if self.storage.length < self.capacity:
self.storage.add_to_tail(item) # adding item to tail
self.current = self.storage.head # setting current to the head item
# if at capacity delete the head item and remove from storage. add new item to back/tail
elif self.storage.length == self.capacity:
to_delete = self.storage.head
self.storage.remove_from_head()
self.storage.add_to_tail(item)
if to_delete == self.current:
self.current = self.storage.tail

def get(self):
# Note: This is the only [] allowed
list_buffer_contents = []

# TODO: Your code here
# current = self.storage.head # starts at the front/head of storage

# while current != None: # loops until end while value is not none
# current = current.next # move on to next item, keep going in the loop
# list_buffer_contents.append(current.value) # add to array

return list_buffer_contents

Expand Down