Skip to content

Brandon Bruce - Sprint Challenge #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
46 changes: 42 additions & 4 deletions names/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,48 @@
duplicates = [] # Return the list of duplicates in this data structure

# Replace the nested for loops below with your improvements
for name_1 in names_1:
for name_2 in names_2:
if name_1 == name_2:
duplicates.append(name_1)
class BSTNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None

# Insert the given value into the tree
def insert(self, value):
if value < self.value:
if self.left is None:
self.left = BSTNode(value)
else:
self.left.insert(value)
elif value >= self.value:
if self.right is None:
self.right = BSTNode(value)
else:
self.right.insert(value)

# Return True if the tree contains the value
# False if it does not
def contains(self, target):
if self.value == target:
return True
elif self.value > target:
if self.left is None:
return False
else:
return self.left.contains(target)
else:
if self.right is None:
return False
else:
return self.right.contains(target)


bst = BSTNode('')
for i in names_1:
bst.insert(i)
for i in names_2:
if bst.contains(i):
duplicates.append(i)

end_time = time.time()
print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n")
Expand Down
8 changes: 7 additions & 1 deletion reverse/reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ def contains(self, value):
return False

def reverse_list(self, node, prev):
pass
while node:
next_node = node.next_node
node.next_node = prev
prev = node
node = next_node
self.head = prev
return node
23 changes: 20 additions & 3 deletions ring_buffer/ring_buffer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
class RingBuffer:
def __init__(self, capacity):
pass
self.capacity = capacity
self.ring = []
self.counter = 0

def append(self, item):
pass
if len(self.ring) < self.capacity:
self.ring.append(item)
else:
self.ring[self.counter] = item
self.counter += 1
if self.counter == self.capacity:
self.counter = 0

def get(self):
pass
return(self.ring)

buffer = RingBuffer(3)
buffer.append('a')
buffer.append('b')
buffer.append('c')
print(buffer.get())
buffer.append('d')
buffer.append('e')
print(buffer.get())