-
Notifications
You must be signed in to change notification settings - Fork 49
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
Erika - Branches #45
base: master
Are you sure you want to change the base?
Erika - Branches #45
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you have made advances in working with list nodes. However it looks like you got a bit stuck. Take a look at my comments and let me know if I can answer any questions.
@@ -19,57 +19,132 @@ 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/linked_list.rb
Outdated
return nil | ||
end | ||
|
||
until @head.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to lose all subsequent elements of the linked list.
You need to have a current element to traverse the list.
return nil if @head.nil?
current = @head
until current.next.nil?
return true if current.data == value
current = current.next
end
return false
lib/linked_list.rb
Outdated
until current.nil? | ||
if max.data < current.data | ||
max = current | ||
current = current.next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current = current.next | |
end | |
current = current.next |
current = current.next | ||
end | ||
end | ||
return max.data | ||
end | ||
|
||
# method to return the min value in the linked list | ||
# returns the data value and not the node | ||
def find_min |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above for suggestions on how to fix this.
current = current.next | ||
end | ||
end | ||
return min.data | ||
end | ||
|
||
|
||
# method that returns the length of the singly linked list | ||
def length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
def get_at_index(index) | ||
raise NotImplementedError | ||
end | ||
|
||
|
||
# method to print all the values in the linked list | ||
def visit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/linked_list.rb
Outdated
until current.nil? | ||
if current.data == value | ||
previous.next = current.next | ||
exit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exit exits the program, you probably meant return
current = current.next | ||
end | ||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
No description provided.