Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

jessicacaley
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a 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

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}"

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)?

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)

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants