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

Carla #22

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

Carla #22

wants to merge 1 commit into from

Conversation

carlabosco
Copy link

No description provided.

@carlabosco carlabosco changed the title Add linked list methods Carla Aug 27, 2019
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.

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

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

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

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

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

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

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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