Skip to content

Finished Sprint #443

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 3 commits 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
32 changes: 32 additions & 0 deletions names/binary_search_tree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class BSTNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None

def insert(self, value):
if value < self.value:
if self.left == None:
self.left = BSTNode(value)
else:
self.left.insert(value)
else:
if self.right == None:
self.right = BSTNode(value)
else:
self.right.insert(value)

def contains(self, target):
if self.value == target:
return True
else:
if target < self.value:
if self.left == None:
return False
else:
return self.left.contains(target)
else:
if self.right == None:
return False
else:
return self.right.contains(target)
11 changes: 7 additions & 4 deletions names/names.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
from binary_search_tree import BSTNode

start_time = time.time()

Expand All @@ -13,10 +14,12 @@
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)
bst = BSTNode("Name")
for name in names_1:
bst.insert(name)
for name in names_2:
if bst.contains(name):
duplicates.append(name)

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
if node is None:
self.head = prev
return

next_node = node.get_next()
node.set_next(prev)
self.reverse_list(next_node, node)
17 changes: 14 additions & 3 deletions ring_buffer/ring_buffer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
class RingBuffer:
def __init__(self, capacity):
pass
self.capacity = capacity
self.storage = []
self.index = 0

def append(self, item):
pass
if len(self.storage) < self.capacity:
self.storage.append(item)
else:
self.storage[self.index] = item

self.index += 1

if self.index == self.capacity:
self.index = 0

def get(self):
pass
return self.storage