Skip to content

Hana#21

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

Hana#21
hanalways wants to merge 1 commit intoAda-C11:masterfrom
hanalways:master

Conversation

@hanalways
Copy link
Copy Markdown

No description provided.

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.

There are a lot of good things here, but some unfinished work as well and some bugs. Take a look at my comments and let me know if you have any questions.

Remember I have office hours and can meet by appointment.

Comment thread lib/linked_list.rb
class LinkedList
def initialize
@head = nil # keep the head private. Not accessible outside this class
@tail = 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.

Nice!

Comment thread lib/linked_list.rb
# end
# @tail = current

print @head.data
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This doesn't need to be in the submission.

Comment thread lib/linked_list.rb
# Space Complexity
def add_last(value)
new_node = Node.new(value)
@tail = new_node
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You should do @tail.next = new_node before this. Then except for checking if the list was empty before, you would be finished. No loop required.

Comment thread lib/linked_list.rb
current = @head

if current
index.times do
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 index is larger than the size of the list?

Comment thread lib/linked_list.rb
raise NotImplementedError
if @head
current = @head
max = 0
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 list is filled with negative numbers? What if it's not a list of integers?

Comment thread lib/linked_list.rb
# Space Complexity
def length
raise NotImplementedError
# CHRIS - this isn't working! I'm pretty sure this is because it's not updating tail, bu
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is because your add_last method isn't updating @tail properly.

Comment thread lib/linked_list.rb
def get_at_index(index)
raise NotImplementedError
def search(value)
current = @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.

What if @head is nil?

Comment thread lib/linked_list.rb
current = @head
index = count - 1

count.times do
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This works, but it's an O(n2) algorithm. Is there a better way?

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