Open
Conversation
CheezItMan
reviewed
Feb 23, 2020
CheezItMan
left a comment
There was a problem hiding this comment.
It looks like you have made advances in working with list nodes. However it looks like you got a bit stuck. Take a look at my comments and let me know if I can answer any questions.
| @@ -19,57 +19,132 @@ 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) | |||
lib/linked_list.rb
Outdated
| return nil | ||
| end | ||
|
|
||
| until @head.nil? |
There was a problem hiding this comment.
This is going to lose all subsequent elements of the linked list.
You need to have a current element to traverse the list.
return nil if @head.nil?
current = @head
until current.next.nil?
return true if current.data == value
current = current.next
end
return false
lib/linked_list.rb
Outdated
| until current.nil? | ||
| if max.data < current.data | ||
| max = current | ||
| current = current.next |
There was a problem hiding this comment.
Suggested change
| current = current.next | |
| end | |
| current = current.next |
|
|
||
| # 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.
See above for suggestions on how to fix this.
|
|
||
|
|
||
| # method that returns the length of the singly linked list | ||
| def length |
|
|
||
|
|
||
| # method to print all the values in the linked list | ||
| def visit |
lib/linked_list.rb
Outdated
| until current.nil? | ||
| if current.data == value | ||
| previous.next = current.next | ||
| exit |
There was a problem hiding this comment.
exit exits the program, you probably meant return
|
|
||
| # method to reverse the singly linked list | ||
| # note: the nodes should be moved and not just the values in the nodes | ||
| def reverse |
added 12 commits
July 9, 2020 13:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.