-
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
Margaret #5
base: master
Are you sure you want to change the base?
Margaret #5
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.
Well done, you hit the major learning goals. Check out my comments below and let me know if you have questions.
@@ -6,158 +6,294 @@ class Node | |||
|
|||
def initialize(value, next_node = nil) | |||
@data = value | |||
@next = next_node | |||
@next = nil |
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.
Not sure why you made this change?
def add_first(value) | ||
new_node = Node.new(value) | ||
|
||
if @head != nil #if list isn't empty |
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.
Even if @head
is nil, wouldn't the line below still work?
def search(value) | ||
raise NotImplementedError | ||
current = @head | ||
while @next != nil |
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.
Don't you mean while current != nil
, and you should be doing current = current.next
# note: the nodes should be moved and not just the values in the nodes | ||
# Time Complexity: 0(n) where n is length of linked list bc we are checking each node | ||
# Space Complexity: constant, extra space needed for variables does not grow as the size of the LL grows | ||
def reverse |
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 Complexity: | ||
# Space Complexity | ||
def find_nth_from_end(n) | ||
#copied from solution branch so tests for reverse could run |
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.
Noted
No description provided.