Conversation
CheezItMan
reviewed
Sep 3, 2019
CheezItMan
left a comment
There was a problem hiding this comment.
You did well on all the methods you completed. There are a few left to do, but this is very well done. Nice work!
| # Time Complexity: O(1) | ||
| # Space Complexity O(1) | ||
| def add_first(value) | ||
| @head = Node.new(value, @head) # i don't fully understand why next_node is @head |
There was a problem hiding this comment.
You're setting next_node to the old value of @head. So the new node links to the start of the old list.
| # printing things to try to trace what's happening | ||
| while current | ||
| puts "------------" | ||
| puts "temporary: #{temporary.data if temporary}" |
There was a problem hiding this comment.
You can remove these when you submit.
| # method to reverse the singly linked list | ||
| # note: the nodes should be moved and not just the values in the nodes | ||
| # Time Complexity: O(n), where n is the length of the list | ||
| # Space Complexity: O(1)? |
There was a problem hiding this comment.
Since you're reversing in place yes it's O(1) in space complexity.
| def find_nth_from_end(n) | ||
| return nil if self.length - 1 < n | ||
|
|
||
| self.get_at_index(self.length - 1 - n) |
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.