Conversation
CheezItMan
reviewed
Sep 1, 2020
CheezItMan
left a comment
There was a problem hiding this comment.
Overall pretty good, some small bugs that I tried to point out here. Let me know if you have questions about them.
Comment on lines
+25
to
+31
| if @head.nil? | ||
| @head = Node.new(value) | ||
| else | ||
| new_nodelet = Node.new(value, @head) | ||
| new_nodelet.next = @head | ||
| @head = new_nodelet | ||
| end |
There was a problem hiding this comment.
You could rewrite this as:
Suggested change
| if @head.nil? | |
| @head = Node.new(value) | |
| else | |
| new_nodelet = Node.new(value, @head) | |
| new_nodelet.next = @head | |
| @head = new_nodelet | |
| end | |
| @head = Node.new(value, @head) |
This way the new node's next points to the old head (which might be nil).
Comment on lines
+36
to
38
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def search(value) |
Comment on lines
+53
to
55
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def find_max |
There was a problem hiding this comment.
Correct, but space complexity would be O(1) since you don't create a new data structure, but just track the greatest value found so far.
Comment on lines
+73
to
75
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def find_min |
Comment on lines
+93
to
95
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def length |
Comment on lines
+115
to
+125
| return nil if @head.nil? | ||
|
|
||
| current = @head | ||
| count = 0 | ||
|
|
||
| until count == index | ||
| current = current.next | ||
| count += 1 | ||
| end | ||
|
|
||
| return current.data |
There was a problem hiding this comment.
What if the length is less than index?
Comment on lines
+129
to
131
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def visit |
Comment on lines
+143
to
145
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def delete(value) |
There was a problem hiding this comment.
What if you are deleting the 1st node?
Comment on lines
+147
to
+156
|
|
||
| last = @head | ||
| current = @head | ||
|
|
||
| until current.data == value || current.nil? | ||
| last = current | ||
| current = current.next | ||
| end | ||
|
|
||
| last.next = current.next |
There was a problem hiding this comment.
Suggested change
| last = @head | |
| current = @head | |
| until current.data == value || current.nil? | |
| last = current | |
| current = current.next | |
| end | |
| last.next = current.next | |
| if @head.data == value | |
| @head = @head.next | |
| return | |
| end | |
| last = nil | |
| current = @head | |
| until current.data == value || current.nil? | |
| last = current | |
| current = current.next | |
| end | |
| unless current.nil? | |
| last.next = current.next | |
| end |
Comment on lines
+161
to
163
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def reverse |
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.