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 - Diana Han #40

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

Branches - Diana Han #40

wants to merge 3 commits into from

Conversation

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

You did pretty well with what you got implemented. Several methods remain unfinished, but what is done works pretty well. Take a look at my comments and let me know any questions you have.

@@ -19,43 +19,97 @@ 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.

👍

@@ -19,43 +19,97 @@ 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 = @head
@head = Node.new(value, current)
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.

👍

else
current = current.next
end
end

Choose a reason for hiding this comment

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

Just for readability I suggest returning false when you can't find it.

Suggested change
end
end
return false

else
current = current.next
end
end
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.

👍

while current
max = current.data if current.data > max
current = current.next
end
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.

👍

while current
min = current.data if current.data < min
current = current.next
end
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.

👍

count += 1
node = node.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.

👍

while current
linked_list += "#{current.data}"
current = current.next
end

Choose a reason for hiding this comment

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

Suggested change
end
end
return linked_list

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