Skip to content

Conversation

@halahaddad1
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 well done. The code works and you can take a look at my comments for suggestions. Let me know if you have questions here.

Comment on lines +24 to 26
# Time Complexity: O(1)
# Space Complexity: O(1)
def add_first(value)

Choose a reason for hiding this comment

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

👍

Comment on lines +40 to 42
# 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 +65 to 67
# Time Complexity: O(N)
# Space Complexity: O(1)
def find_max

Choose a reason for hiding this comment

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

👍

Comment on lines +92 to 94
# Time Complexity: O(N)
# Space Complexity: O(1)
def find_min

Choose a reason for hiding this comment

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

👍

Comment on lines +119 to 121
# 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 +122 to +134
length = 1
current = @head
if current.nil?
return 0
elsif current.next.nil?
return 1
else
while current.next != nil
length +=1
current = current.next
end
end
return length

Choose a reason for hiding this comment

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

This could be simplified a bit:

Suggested change
length = 1
current = @head
if current.nil?
return 0
elsif current.next.nil?
return 1
else
while current.next != nil
length +=1
current = current.next
end
end
return length
len = 0
current = @head
until current.nil?
len += 1
current = current.next
end
return len

Comment on lines +140 to 142
# Time Complexity: O(N)
# Space Complexity: O(1)
def get_at_index(index)

Choose a reason for hiding this comment

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

👍

Comment on lines +166 to 168
# 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 +184 to +199
current = @head
while current != nil
if @head.next.nil? && @head.data == value
@head = nil
elsif @head.next != nil && @head.data == value
@head = @head.next
elsif current.next != nil && current.prev != nil && current.data == value
prevn = current.prev
nextn = current.next
prevn.next = nextn
nextn.prev = prevn
elsif !current.prev.nil? && current.data == value
current.prev.next = current.next
end
current = current.next
end

Choose a reason for hiding this comment

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

This is a bit overcomplicated

Suggested change
current = @head
while current != nil
if @head.next.nil? && @head.data == value
@head = nil
elsif @head.next != nil && @head.data == value
@head = @head.next
elsif current.next != nil && current.prev != nil && current.data == value
prevn = current.prev
nextn = current.next
prevn.next = nextn
nextn.prev = prevn
elsif !current.prev.nil? && current.data == value
current.prev.next = current.next
end
current = current.next
end
if @head.data == value
@head = @head.next
return
end
current = @head
previous = nil
until current.nil?
if current.data == value
previous.next = current.next
return
end
previous = current
current = current.next
end

Comment on lines +204 to 206
# 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.

👍

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