-
Notifications
You must be signed in to change notification settings - Fork 68
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
C15 - Christian - linked-list #40
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.
Overall not bad Christian, I left some notes but you hit most of the learning goals here. Take a look at my comments and let me know what questions you have.
# Time Complexity: ? | ||
# Space Complexity: ? | ||
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/space complexity
# Time Complexity:O(1) | ||
# Space Complexity: O(n) | ||
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.
👍 Space complexity is O(1) because you're not creating a bunch of nodes (always just one).
# Time Complexity: O(n) | ||
# Space Complexity: 0 | ||
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.
👍
# method that returns the length of the singly linked list | ||
# Time Complexity: ? | ||
# Space Complexity: ? | ||
def length(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/space complexity?
# Time Complexity: ? | ||
# Space Complexity: ? | ||
def get_at_index(self, index): |
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/space complexity?
Good use of the length()
method
# Time Complexity: ? | ||
# Space Complexity: ? | ||
def delete(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/space complexity?
while current_node != None: | ||
if current_node.next: | ||
if current_node.next.value == value: | ||
print(current_node.value, current_node.next.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 delete the print stmts
print(current_node.value, current_node.next.value) |
current_node.next = current_node.next.next | ||
return | ||
current_node = current_node.next | ||
print(current_node.value, current_node.next.value, "last") |
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.
print(current_node.value, current_node.next.value, "last") |
def visit(self): | ||
helper_list = [] | ||
current = self.head | ||
# 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.
For visit
you can:
- Create an empty list
- Traverse the linked list like you did previously and at each iteration you can append the current value to the list
- You can then
return ", ".join(the_list)
|
||
print(", ".join(helper_list)) | ||
# print(", ".join(helper_list)) | ||
|
||
# method to reverse the singly linked list | ||
# note: the nodes should be moved and not just the values in the nodes | ||
# Time Complexity: ? | ||
# Space Complexity: ? | ||
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.
Just noting this isn't done.
No description provided.