Open
Conversation
CheezItMan
reviewed
Feb 23, 2020
CheezItMan
left a comment
There was a problem hiding this comment.
Several of your methods work really well and you seem to have a grasp on traversing a linked list. That said as you noted you got stuck at one point and several methods don't work. See my comments and let me know what questions you have.
| @@ -19,48 +19,105 @@ 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) | |||
| previous = @head | ||
| current = @head | ||
|
|
||
| until current.nil? |
There was a problem hiding this comment.
I'd suggest going until current.next.nil?, and then setting current.next equal to a new node.
| end | ||
|
|
||
| # method that inserts a given value as a new last node in the linked list | ||
| def add_last(value) |
| end | ||
|
|
||
| previous = @head | ||
| current = @head |
There was a problem hiding this comment.
You should also put in a check to make sure that the node we're deleting is not the head.
| # end | ||
|
|
||
| # method to print all the values in the linked list | ||
| def visit |
| # method that returns the value at a given index in the linked list | ||
| # index count starts at 0 | ||
| # returns nil if there are fewer nodes in the linked list than the index value | ||
| def get_at_index(index) |
|
|
||
|
|
||
| # method that returns the length of the singly linked list | ||
| def length |
|
|
||
| # method to return the min value in the linked list | ||
| # returns the data value and not the node | ||
| def find_min |
|
|
||
| # method to return the max value in the linked list | ||
| # returns the data value and not the node | ||
| def find_max |
|
|
||
| # method to find if the linked list contains a node with specified value | ||
| # returns true if found, false otherwise | ||
| def search(value) |
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.