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

Branches - Eve #30

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Branches - Eve #30

wants to merge 5 commits into from

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

single = single.next
end
end
return false
end


# 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


# Additional Exercises
# returns the value in the first node
# returns nil if the list is empty
def get_first
raise NotImplementedError
return nil if !@head
return @head.data
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.

👍

last_node.next = Node.new(value)
else
@head = Node.new(value)
end
end

# 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

return last_node.data
else
return last_node
end
end

# 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