Open
Conversation
CheezItMan
reviewed
Feb 23, 2020
CheezItMan
left a comment
There was a problem hiding this comment.
Nice work, you hit most the learning goals here. That said you had some bugs in here, most notably in add_first. Take a look at my notes and let me know what questions you have.
| # 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) | ||
| @head = Node.new(value) |
There was a problem hiding this comment.
You need to attach the new node to the rest of the list.
Suggested change
| @head = Node.new(value) | |
| @head = Node.new(value, @head) | |
| def delete(value) | ||
| raise NotImplementedError | ||
|
|
||
| return current.data |
There was a problem hiding this comment.
current might be nil
Suggested change
| return current.data | |
| return nil if current.nil? | |
| return current.data |
| end | ||
|
|
||
| # method to print all the values in the linked list | ||
| def visit |
| end | ||
|
|
||
| # method to delete the first node found with specified value | ||
| def delete(value) |
|
|
||
| # method to reverse the singly linked list | ||
| # note: the nodes should be moved and not just the values in the nodes | ||
| def reverse |
|
|
||
| # find the nth node from the end and return it s value | ||
| # assume indexing starts at 0 while counting to n | ||
| def find_nth_from_end(n) |
| # Additional Exercises | ||
| # returns the value in the first node | ||
| # returns nil if the list is empty | ||
| def get_first |
| end | ||
|
|
||
| # method that inserts a given value as a new last node in the linked list | ||
| def add_last(value) |
|
|
||
| # method that returns the value of the last node in the linked list | ||
| # returns nil if the linked list is empty | ||
| def get_last |
|
|
||
| # method to insert a new node with specific data value, assuming the linked | ||
| # list is sorted in ascending order | ||
| def insert_ascending(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.