diff --git a/.idea/Sprint-Challenge--Data-Structures-Python.iml b/.idea/Sprint-Challenge--Data-Structures-Python.iml new file mode 100644 index 000000000..d0876a78d --- /dev/null +++ b/.idea/Sprint-Challenge--Data-Structures-Python.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 000000000..105ce2da2 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..a2e120dcc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..e549fe287 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..94a25f7f4 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/names/names.py b/names/names.py index ea158997f..2fa4e9f64 100644 --- a/names/names.py +++ b/names/names.py @@ -13,16 +13,21 @@ duplicates = [] # Return the list of duplicates in this data structure # Replace the nested for loops below with your improvements +#def findDuplicates(new_list, list1, list2): +for name in names_1: + if name in names_2: + duplicates.append(name) +""" for name_1 in names_1: for name_2 in names_2: if name_1 == name_2: duplicates.append(name_1) - +""" end_time = time.time() print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n") print (f"runtime: {end_time - start_time} seconds") # ---------- Stretch Goal ----------- # Python has built-in tools that allow for a very efficient approach to this problem -# What's the best time you can accomplish? Thare are no restrictions on techniques or data +# What's the best time you can accomplish? There are no restrictions on techniques or data # structures, but you may not import any additional libraries that you did not write yourself. diff --git a/reverse/reverse.py b/reverse/reverse.py index 6116252d1..5583a3a56 100644 --- a/reverse/reverse.py +++ b/reverse/reverse.py @@ -39,4 +39,16 @@ def contains(self, value): return False def reverse_list(self, node, prev): - pass + if not self.head and not prev: + return None + else: + next = node.next_node + + while node: + node.next_node = prev + prev = node + node = next + if next: + next = next.next_node + + self.head = prev diff --git a/ring_buffer/ring_buffer.py b/ring_buffer/ring_buffer.py index 37e9fb0dd..643b1ba34 100644 --- a/ring_buffer/ring_buffer.py +++ b/ring_buffer/ring_buffer.py @@ -1,9 +1,32 @@ class RingBuffer: def __init__(self, capacity): - pass + self.capacity = capacity + self.items = [] + self.counter = 0 def append(self, item): - pass + if len(self.items) == self.capacity: + del self.items[self.counter] + self.items.insert(self.counter, item) + if self.counter == 4: + self.counter = 0 + else: + self.counter += 1 + else: + self.items.append(item) def get(self): - pass \ No newline at end of file + return self.items + +x=RingBuffer(5) +x.append(1); x.append(2); x.append(3); x.append(4) +print(x.get()) +x.append(5) +print(x.get()) +x.append(6) +print(x.get()) +x.append(7); x.append(8); x.append(9); x.append(10) +print(x.get()) +x.append(8); x.append(9); x.append(10); x.append(11); x.append(12) +print(x.get()) +