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

Erika - Branches #45

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

Erika - Branches #45

wants to merge 13 commits into from

Conversation

emaust
Copy link

@emaust emaust commented Feb 23, 2020

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.

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)

Choose a reason for hiding this comment

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

👍

return nil
end

until @head.nil?

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

until current.nil?
if max.data < current.data
max = current
current = current.next

Choose a reason for hiding this comment

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

Suggested change
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

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

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

Choose a reason for hiding this comment

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

👍

until current.nil?
if current.data == value
previous.next = current.next
exit

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

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