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

Leaves - Bri #43

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

Leaves - Bri #43

wants to merge 1 commit into from

Conversation

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

Several of your methods work really well and you seem to have a grasp on traversing a linked list. That said as you noted you got stuck at one point and several methods don't work. See my comments and let me know what questions you have.

@@ -19,48 +19,105 @@ 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)

Choose a reason for hiding this comment

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

👍

previous = @head
current = @head

until current.nil?

Choose a reason for hiding this comment

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

I'd suggest going until current.next.nil?, and then setting current.next equal to a new node.

return nil
else
return @head.data
end
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

previous = @head
current = @head

Choose a reason for hiding this comment

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

You should also put in a check to make sure that the node we're deleting is not the head.

end
# end

# method to print all the values in the linked list
def visit

Choose a reason for hiding this comment

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

👍

count += 1
current = current.next
end
return count
end

# method that returns the value at a given index in the linked list
# index count starts at 0
# returns nil if there are fewer nodes in the linked list than the index value
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.

👍

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

👍

temp = temp.next
end
return false
end

# method to return the max value in the linked list
# returns the data value and not the node
def find_max

Choose a reason for hiding this comment

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

👍

@@ -19,48 +19,105 @@ 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
current_node = Node.new(value, @head)
@head = current_node
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.

👍

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