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

Branches - Monick #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Branches - Monick #24

wants to merge 1 commit into from

Conversation

mfunkemomo
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.

Nice work, you hit all the learning goals here. Well done. Take a look at my comments and let me know if you have questions. The methods you have written all work and you've demonstrated an understanding of how to implement a Linked List.

@@ -19,38 +19,88 @@ def initialize
# method to add a new node with the specific data value in the linked list
# insert the new node at the beginning of the linked list
def add_first(value)
raise NotImplementedError
@head = Node.new(value, @head)
end

# method to find if the linked list contains a node with specified value
# returns true if found, false otherwise
def search(value)

Choose a reason for hiding this comment

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

👍

end

# method to return the max value in the linked list
# returns the data value and not the node
def find_max
raise NotImplementedError
return nil if @head.nil?
max = 0

Choose a reason for hiding this comment

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

What if it's a linked list of negative values, or non-integers?

Suggested change
max = 0
max = @head.data

current = current.next
end

return max
end

# method to return the min value in the linked list
# returns the data value and not the node
def find_min

Choose a reason for hiding this comment

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

👍

current = current.next
end

return min
end


# method that returns the length of the singly linked list
def length

Choose a reason for hiding this comment

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

👍

end


# method that returns the length of the singly linked list
def length
raise NotImplementedError
count = 0
return count if @head.nil?

Choose a reason for hiding this comment

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

Do you need this line?

@head = current.next
else
prev.next = current.next
end
end

# method to reverse the singly linked list
# note: the nodes should be moved and not just the values in the nodes
def reverse

Choose a reason for hiding this comment

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

👍

Comment on lines +163 to +166
until current.next.nil?
length += 1
current = current.next
end

Choose a reason for hiding this comment

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

Why not use the length method to calculate the length of the list?

@@ -94,18 +187,36 @@ def has_cycle
# returns the value in the first node
# returns nil if the list is empty
def get_first

Choose a reason for hiding this comment

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

👍

@@ -94,18 +187,36 @@ def has_cycle
# returns the value in the first node
# returns nil if the list is empty
def get_first
raise NotImplementedError
return nil if @head.nil?
return @head.data
end

# method that inserts a given value as a new last node in the linked list
def add_last(value)

Choose a reason for hiding this comment

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

👍

end

current.next = Node.new(value, nil)
end
end

# method that returns the value of the last node in the linked list
# returns nil if the linked list is empty
def get_last

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