-
Notifications
You must be signed in to change notification settings - Fork 49
Branches - Eve #30
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
base: master
Are you sure you want to change the base?
Branches - Eve #30
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
No description provided.