-
Notifications
You must be signed in to change notification settings - Fork 28
sai's linked list #9
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
base: master
Are you sure you want to change the base?
Conversation
| puts "Not implemented" | ||
|
|
||
| current = @head | ||
| max = current.data |
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.
| def find_min | ||
| puts "Not implemented" | ||
| current = @head | ||
| min = current.data |
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 with find_max wrt nil dereference.
| size = 0 | ||
| until size == n do | ||
| size += 1 | ||
| 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.
This will have an issue if n is greater than number of nodes in the linked list. Always check to ensure that @Head is not nil. Then, in the loop, check to ensure that current is not nil before accessing current.next.
| current = current.next | ||
| end | ||
| else | ||
| 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.
What happens when @Head is nil? What happens when @head.data > value?
| current = @head | ||
|
|
||
| until i == n do | ||
| 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 to ensure that current is not nil before doing a .next on it.
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.
In other words, make your code work for cases where number of nodes is less than n.
Linked Lists
Congratulations! You're submitting your assignment.
Comprehension Questions
What is the time and space complexity for each method you implemented? Provide justification.