-
Notifications
You must be signed in to change notification settings - Fork 47
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
Ports - Jessica #19
base: master
Are you sure you want to change the base?
Ports - Jessica #19
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
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.
Very good use of existing methods!
No description provided.