Skip to content

Conversation

@tofuandeve
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.

Nice work, you hit all the learning goals here. Well done. I really like how you worked to implement the DoublyLinked list. Take a look at my comments and let me know what questions you have. You put together a lot of really elegant code here, it was hard for me to find things to comment on. Impressive!

class DoublyLinkedList
def initialize
@head = nil
@tail = nil

Choose a reason for hiding this comment

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

Great idea to have a @tail attribute!

# raise NotImplementedError
end

def add_first(value)

Choose a reason for hiding this comment

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

👍

@size += 1
end

def add_last(value)

Choose a reason for hiding this comment

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

👍

@size += 1
end

def get_first

Choose a reason for hiding this comment

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

👍


def get_last
return @tail.data if @tail
return @tail

Choose a reason for hiding this comment

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

This method works, but if @tail is nil, I suggest explicitly returning nil here.

Suggested change
return @tail
return nil

# Additional Exercises
# returns the value in the first node
# returns nil if the list is empty
def get_first

Choose a reason for hiding this comment

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

👍

end

# method that inserts a given value as a new last node in the linked list
def add_last(value)

Choose a reason for hiding this comment

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

👍


# method that returns the value of the last node in the linked list
# returns nil if the linked list is empty
def get_last

Choose a reason for hiding this comment

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

👍

if last_node
return last_node.data
else
return last_node

Choose a reason for hiding this comment

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

Suggested change
return last_node
return nil


# method to insert a new node with specific data value, assuming the linked
# list is sorted in ascending order
def insert_ascending(value)

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