From 347febf94e99e676ba5c8558dce498dc7842764f Mon Sep 17 00:00:00 2001 From: Maria Trujillo Date: Fri, 11 Sep 2020 18:53:36 +0200 Subject: [PATCH 1/3] finished ring buffer --- ring_buffer/ring_buffer.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ring_buffer/ring_buffer.py b/ring_buffer/ring_buffer.py index 37e9fb0dd..d5685d40a 100644 --- a/ring_buffer/ring_buffer.py +++ b/ring_buffer/ring_buffer.py @@ -1,9 +1,19 @@ class RingBuffer: def __init__(self, capacity): - pass + self.capacity = capacity + self.data = [None]*capacity + self.current = 0 def append(self, item): - pass + + self.data[self.current] = item + + self.current += 1 + if self.current == self.capacity: + self.current = 0 + def get(self): - pass \ No newline at end of file + a = [i for i in self.data if i is not None] + + return a \ No newline at end of file From b36032b5c57a441d7a23a2ffa75e6c3f929f2e08 Mon Sep 17 00:00:00 2001 From: Maria Trujillo Date: Fri, 11 Sep 2020 19:20:45 +0200 Subject: [PATCH 2/3] finished names.py --- names/names.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/names/names.py b/names/names.py index ea158997f..469de8432 100644 --- a/names/names.py +++ b/names/names.py @@ -13,10 +13,15 @@ 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) +# for name_1 in names_1: +# for name_2 in names_2: +# if name_1 == name_2: +# duplicates.append(name_1) + + +a = [i for i in names_1 if i in names_2] + +duplicates = a end_time = time.time() print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n") From 3847cfd52422c11c031fc5459c62d0abb45719b4 Mon Sep 17 00:00:00 2001 From: Maria Trujillo Date: Fri, 11 Sep 2020 21:23:41 +0200 Subject: [PATCH 3/3] finished reverse --- reverse/reverse.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/reverse/reverse.py b/reverse/reverse.py index 6116252d1..5b753d423 100644 --- a/reverse/reverse.py +++ b/reverse/reverse.py @@ -39,4 +39,26 @@ def contains(self, value): return False def reverse_list(self, node, prev): - pass + + current = self.head + + # if its empty + if not current: + return + + # while theres something after the head + while current.next_node: + # store the next node + temp = current.next_node + # switch positions + current.next_node = prev + # move along the line + prev = current + current = temp + # since theres nothing after the last current, set the next node to prev which is none + current.next_node = prev + + self.head = current + + +