-
Notifications
You must be signed in to change notification settings - Fork 47
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
Hana #21
base: master
Are you sure you want to change the base?
Hana #21
Conversation
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.
There are a lot of good things here, but some unfinished work as well and some bugs. Take a look at my comments and let me know if you have any questions.
Remember I have office hours and can meet by appointment.
@@ -14,79 +15,213 @@ def initialize(value, next_node = nil) | |||
class LinkedList | |||
def initialize | |||
@head = nil # keep the head private. Not accessible outside this class | |||
@tail = nil |
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.
Nice!
# end | ||
# @tail = current | ||
|
||
print @head.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.
This doesn't need to be in the submission.
# Space Complexity | ||
def add_last(value) | ||
new_node = Node.new(value) | ||
@tail = new_node |
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.
You should do @tail.next = new_node
before this. Then except for checking if the list was empty before, you would be finished. No loop required.
current = @head | ||
|
||
if current | ||
index.times do |
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 if index is larger than the size of the list?
raise NotImplementedError | ||
if @head | ||
current = @head | ||
max = 0 |
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 if the list is filled with negative numbers? What if it's not a list of integers?
# Time Complexity: | ||
# Space Complexity | ||
def length | ||
raise NotImplementedError | ||
# CHRIS - this isn't working! I'm pretty sure this is because it's not updating tail, bu |
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 is because your add_last
method isn't updating @tail
properly.
def get_at_index(index) | ||
raise NotImplementedError | ||
def search(value) | ||
current = @head |
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 if @head
is nil?
|
||
count.times do |
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 works, but it's an O(n2) algorithm. Is there a better way?
No description provided.