Skip to content
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

Time - Alex #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Time - Alex #26

wants to merge 4 commits into from

Conversation

codesrobertson
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +53 to 55
# Time Complexity: O(n)
# Space Complexity: O(n)
def find_max

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto with find_max

Comment on lines +93 to 95
# Time Complexity: O(n)
# Space Complexity: O(1)
def length

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the length is less than index?

Comment on lines +129 to 131
# Time Complexity: O(n)
# Space Complexity: O(1)
def visit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +143 to 145
# Time Complexity: O(n)
# Space Complexity: O(n)
def delete(value)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nicely done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants