-
Notifications
You must be signed in to change notification settings - Fork 28
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
Jou-Jou's Linked Lists #5
base: master
Are you sure you want to change the base?
Conversation
end | ||
|
||
# method to return the max value in the linked list | ||
# returns the data value and not the node | ||
def find_max | ||
puts "Not implemented" | ||
current = @head | ||
max = current |
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.
What is head is nil? You won't be able to return max.data in that case. Always check for nil before dereferencing.
end | ||
|
||
# method to return the min value in the linked list | ||
# returns the data value and not the node | ||
def find_min | ||
puts "Not implemented" | ||
current = @head | ||
min = current.data # not sure why in the previous menthod couldn't use .data here |
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.
Same comment as above. Check if current is nil before accessing current.data.
i = 0 | ||
|
||
until i == n | ||
current = current.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.
Check for nil before moving to next. Check for the case where the linked list has less than n nodes.
Linked Lists
Congratulations! You're submitting your assignment.
Comprehension Questions
What is the time and space complexity for each method you implemented? Provide justification.