Skip to content

Conversation

hanalways
Copy link

No description provided.

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.

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.

class LinkedList
def initialize
@head = nil # keep the head private. Not accessible outside this class
@tail = nil

Choose a reason for hiding this comment

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

Nice!

# end
# @tail = current

print @head.data

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.

# Space Complexity
def add_last(value)
new_node = Node.new(value)
@tail = new_node

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.

current = @head

if current
index.times do

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?

raise NotImplementedError
if @head
current = @head
max = 0

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?

# Space Complexity
def length
raise NotImplementedError
# CHRIS - this isn't working! I'm pretty sure this is because it's not updating tail, bu

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.

def get_at_index(index)
raise NotImplementedError
def search(value)
current = @head

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?

current = @head
index = count - 1

count.times do

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