C15 - Christian - linked-list#40
Open
Crintion wants to merge 2 commits intoAda-C15:masterfrom
Open
Conversation
CheezItMan
reviewed
Oct 7, 2021
CheezItMan
left a comment
There was a problem hiding this comment.
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.
Comment on lines
16
to
18
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| def get_first(self): |
Comment on lines
+27
to
29
| # Time Complexity:O(1) | ||
| # Space Complexity: O(n) | ||
| def add_first(self, value): |
There was a problem hiding this comment.
👍 Space complexity is O(1) because you're not creating a bunch of nodes (always just one).
Comment on lines
+35
to
37
| # Time Complexity: O(n) | ||
| # Space Complexity: 0 | ||
| def search(self, value): |
Comment on lines
46
to
49
| # method that returns the length of the singly linked list | ||
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| def length(self): |
Comment on lines
60
to
62
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| def get_at_index(self, index): |
There was a problem hiding this comment.
👍 time/space complexity?
Good use of the length() method
Comment on lines
118
to
120
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| def delete(self, value): |
| 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.
You can delete the print stmts
Suggested change
| 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.
Suggested change
| 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.
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)
| # note: the nodes should be moved and not just the values in the nodes | ||
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| def reverse(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.