Scissors - Mai T.#59
Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
Some issues here. Take a look at my comments and let me know what questions you have.
| # Time Complexity: O(1) | ||
| # Space Complexity: O(n) | ||
| def get_first(self): |
There was a problem hiding this comment.
👍 However space complexity is O(1) since it doesn't add any nodes to the list.
| # Time Complexity: O(1) | ||
| # Space Complexity: O(n) | ||
| def add_first(self, value): |
There was a problem hiding this comment.
👍 Also O(1) for space complexity since the method only ever adds 1 node to the list.
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def search(self, value): |
There was a problem hiding this comment.
👍 However the space complexity is O(1) since it doesn't increase the size of the list.
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def length(self): |
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def get_at_index(self, index): |
| current_node = self.head | ||
| if current_node.value == value: |
There was a problem hiding this comment.
You need to check to see if the linked list is empty so
if self.head == None
return| self.head = current_node.next | ||
| return | ||
| while current_node != None: | ||
| if current_node.next.value == value: |
There was a problem hiding this comment.
If you want to check current_node.next.value you should also check to see if current_node.next is None
| # Space Complexity: ? | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def delete(self, value): |
There was a problem hiding this comment.
| previous_node = None | ||
| current_node = self.head | ||
| while current_node != None: | ||
| next_node = current_node |
There was a problem hiding this comment.
| next_node = current_node | |
| next_node = current_node.next | |
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def reverse(self): |
No description provided.