-
Notifications
You must be signed in to change notification settings - Fork 87
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
Nicole Washington:Maple #77
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: constant, no traversing needed | ||
# Space Complexity: constant, no new data structures | ||
def get_first(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: constant | ||
# Space Complexity: constant | ||
def add_first(self, value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: linear | ||
# Space Complexity: constant | ||
def search(self, value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
if self.head is None: | ||
return False | ||
current_node = self.head | ||
target_node = Node(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can create a new node for the target, but it's not necessary. See my suggestion on line 45 ⬇️
|
||
# traverse list til reach target node or end of list | ||
while current_node: | ||
if current_node.value == target_node.value: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current_node.value
is an integer, so instead of creating a new node target_node
that has value value
, you can just compare the current node's value directly to the passed in value
.
if current_node.value == target_node.value: | |
if current_node.value == value: | |
def add_last(self, value): | ||
pass | ||
if self.head is None: | ||
self.head = value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 self.head
should be equal to a node object, not an integer like value
new_tail_node = prev_node | ||
current_node.next = new_tail_node | ||
new_tail_node.next = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, after creating the new_tail_node
on line 115, you are overwriting it with prev_node
which, once the while loop is finished executing, should be the current tail node.
Once the while loop is finished executing current_node
is going to be the node after the the current tail, aka None
.
Instead, try pointing the current tail (prev_node
) to new_tail_node
while current_node: | ||
if current_node.value > max_node.value: | ||
max_node = current_node | ||
current_node = current_node.next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔You're creating an infinite loop here since you only reassign current_node
to the next node in the list if current_node.value > max_node.value
# Time Complexity: linear | ||
# Space Complexity: constant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💫 Correct on the time and space complexity, however see my comments below ⬇️
next_node = current_node.next | ||
target_value = value | ||
if current_node.value == target_value: | ||
current_node = current_node.next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes current_node
equal to what was the second node in the list, but it doesn't redirect self.head
to point at the second node in the list
current_node = current_node.next | |
self.head = current_node.next | |
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: linear | ||
# Space Complexity: linear | ||
def visit(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: linear | ||
# Space Complexity: constant | ||
def reverse(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨
Linked List