-
Notifications
You must be signed in to change notification settings - Fork 49
Leaves - Dominique #25
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?
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 most of the learning goals here. Not bad. Take a look at my comments and let me know if you have questions. The methods you have written all work, except for delete
and you've demonstrated an understanding of how to implement a Linked List, but you still have some things to work on. Take a look at my suggestions and let me know what questions you have.
@@ -19,54 +19,154 @@ def initialize | |||
# method to add a new node with the specific data value in the linked list | |||
# insert the new node at the beginning of the linked list | |||
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.
👍
new_node.next = @head | ||
|
||
@head = new_node | ||
# head is not a node, it is just a variable that refers to the first node | ||
end | ||
|
||
# method to find if the linked list contains a node with specified value | ||
# returns true if found, false otherwise | ||
def search(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.
👍
current = current.next | ||
end | ||
|
||
return false | ||
end | ||
|
||
# method to return the max value in the linked list | ||
# returns the data value and not the node | ||
def find_max |
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.
👍
current = current.next | ||
end | ||
|
||
return max | ||
end | ||
|
||
# method to return the min value in the linked list | ||
# returns the data value and not the node | ||
def find_min |
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 | ||
|
||
return min | ||
end | ||
|
||
# method that returns the length of the singly linked list | ||
def length |
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 | ||
|
||
until current == nil | ||
if current.next.data == 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.
if current.next.data == value | |
if !current.next.nil? && current.next.data == value |
current = current.next | ||
end | ||
|
||
return linked_list_array | ||
end | ||
|
||
# method to delete the first node found with specified value | ||
def delete(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.
raise NotImplementedError | ||
return nil if @head == nil | ||
|
||
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.
👍
current = current.next | ||
end | ||
current.next = new_node | ||
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.
👍
|
||
until current == nil | ||
if current.next.data == value | ||
current.next == current.next.next |
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.
Small bug here
current.next == current.next.next | |
current.next = current.next.next |
No description provided.