Skip to content

Carla#22

Open
carlabosco wants to merge 1 commit intoAda-C11:masterfrom
carlabosco:master
Open

Carla#22
carlabosco wants to merge 1 commit intoAda-C11:masterfrom
carlabosco:master

Conversation

@carlabosco
Copy link
Copy Markdown

No description provided.

@carlabosco carlabosco changed the title Add linked list methods Carla Aug 27, 2019
Copy link
Copy Markdown

@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!

Comment thread lib/linked_list.rb
def add_first(value)
raise NotImplementedError
node = Node.new(value)
if @head != nil
Copy link
Copy Markdown

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?

Comment thread lib/linked_list.rb
def search(value)
raise NotImplementedError
current = @head
return false if !current.next
Copy link
Copy Markdown

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?

Comment thread lib/linked_list.rb
current = @head
return false if !current.next

while current.next != nil
Copy link
Copy Markdown

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?

Comment thread lib/linked_list.rb
raise NotImplementedError
return if @head.nil?
current = @head
max = nil
Copy link
Copy Markdown

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

Comment thread lib/linked_list.rb
while current != nil
if current.data > max
max = current.data
else
Copy link
Copy Markdown

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?

Comment thread lib/linked_list.rb

while current != nil
if current.data == value
if @head.data == value
Copy link
Copy Markdown

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?

Comment thread lib/linked_list.rb
# Space Complexity: O(1)
def delete(value)
raise NotImplementedError
return if !@head
Copy link
Copy Markdown

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

Comment thread lib/linked_list.rb
# Space Complexity
# Time Complexity: linear
# Space Complexity: O(1)
def reverse
Copy link
Copy Markdown

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