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 - Julia Bouvier #35

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

Conversation

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

Nice work, you hit all the learning goals here. Well done. Take a look at my comments and let me know if you have questions. The methods you have written all work and you've demonstrated an understanding of how to implement a Linked List.

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

👍

return true if current.data == value
current = current.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.

👍

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

👍

raise NotImplementedError
current = @head
length = 0
return 0 if current.nil?

Choose a reason for hiding this comment

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

Do you need this line?


until fast.nil?
slow = slow.next
fast = fast.next.next

Choose a reason for hiding this comment

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

Just in case fast.next is nil.

Suggested change
fast = fast.next.next
fast = fast.next.nil? ? fast.next : fast.next.next

fast = fast.next.next
return true if slow == fast
end
return false
end


# Additional Exercises
# returns the value in the first node
# returns nil if the list is empty
def get_first

Choose a reason for hiding this comment

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

👍

current = @head

return nil if current.nil?
return @head.data
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.

👍

current = current.next
end

current.next = Node.new(value)
end

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

Choose a reason for hiding this comment

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

👍

until current.next.nil?
current = current.next
end
return current.data
end

# method to insert a new node with specific data value, assuming the linked
# list is sorted in ascending order
def insert_ascending(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