-
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
Carla #22
base: master
Are you sure you want to change the base?
Carla #22
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.
Not bad, some of it is unfinished, but you hit the major learning goals here. You also did well identify the Big-O of each method. Nice work!
def add_first(value) | ||
raise NotImplementedError | ||
node = Node.new(value) | ||
if @head != 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.
Does it matter if @head
is nil
?
def search(value) | ||
raise NotImplementedError | ||
current = @head | ||
return false if !current.next |
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.
What about if value
was at the head?
current = @head | ||
return false if !current.next | ||
|
||
while current.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.
What if the value is in the last node, where it's next is nil
?
raise NotImplementedError | ||
return if @head.nil? | ||
current = @head | ||
max = 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.
It would be better if you set max = @head.data
while current != nil | ||
if current.data > max | ||
max = current.data | ||
else |
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.
Do you need an else here?
|
||
while current != nil | ||
if current.data == value | ||
if @head.data == value |
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.
Does this @head.data == value
need to be in the loop?
def delete(value) | ||
raise NotImplementedError | ||
return if !@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.
There's a test failing for this, but that's because the test uses add_last
# Time Complexity: | ||
# Space Complexity | ||
# Time Complexity: linear | ||
# Space Complexity: O(1) | ||
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.
👍
No description provided.