Skip to content

Leaves - Dominique #25

Open
dtaylor73 wants to merge 2 commits into
Ada-C12:masterfrom
dtaylor73:master
Open

Leaves - Dominique #25
dtaylor73 wants to merge 2 commits into
Ada-C12:masterfrom
dtaylor73:master

Conversation

@dtaylor73
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@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 most of the learning goals here. Not bad. Take a look at my comments and let me know if you have questions. The methods you have written all work, except for delete and you've demonstrated an understanding of how to implement a Linked List, but you still have some things to work on. Take a look at my suggestions and let me know what questions you have.

Comment thread lib/linked_list.rb
@@ -19,54 +19,154 @@ 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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread lib/linked_list.rb

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

Choose a reason for hiding this comment

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

👍

Comment thread lib/linked_list.rb

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

Choose a reason for hiding this comment

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

👍

Comment thread lib/linked_list.rb

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

Choose a reason for hiding this comment

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

👍

Comment thread lib/linked_list.rb
end

# method that returns the length of the singly linked list
def length
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread lib/linked_list.rb
end

until current == nil
if current.next.data == value
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if current.next.data == value
if !current.next.nil? && current.next.data == value

Comment thread lib/linked_list.rb
end

# method to delete the first node found with specified value
def delete(value)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ One small correction to make.

Comment thread lib/linked_list.rb
end

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

Choose a reason for hiding this comment

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

👍

Comment thread lib/linked_list.rb

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

Choose a reason for hiding this comment

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

👍

Comment thread lib/linked_list.rb

until current == nil
if current.next.data == value
current.next == current.next.next
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Small bug here

Suggested change
current.next == current.next.next
current.next = current.next.next

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