-
Notifications
You must be signed in to change notification settings - Fork 49
Dani - Leaves #33
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
base: master
Are you sure you want to change the base?
Dani - Leaves #33
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -19,54 +19,125 @@ 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 | ||||||
new_node = Node.new(value, @head) | ||||||
@head = new_node | ||||||
end | ||||||
|
||||||
# method to find if the linked list contains a node with specified value | ||||||
# returns true if found, false otherwise | ||||||
def search(value) | ||||||
raise NotImplementedError | ||||||
return false if @head == nil | ||||||
|
||||||
current = @head | ||||||
found = false | ||||||
until current == nil | ||||||
if current.data == value | ||||||
found = true | ||||||
break | ||||||
end | ||||||
|
||||||
current = current.next | ||||||
end | ||||||
return found | ||||||
end | ||||||
|
||||||
# method to return the max value in the linked list | ||||||
# returns the data value and not the node | ||||||
def find_max | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||||||
raise NotImplementedError | ||||||
return nil if @head == nil | ||||||
|
||||||
current = @head | ||||||
max = current.data | ||||||
|
||||||
until current == nil | ||||||
if current.data > max | ||||||
max = current.data | ||||||
end | ||||||
current = current.next | ||||||
end | ||||||
return max | ||||||
end | ||||||
|
||||||
# method to return the min value in the linked list | ||||||
# returns the data value and not the node | ||||||
def find_min | ||||||
raise NotImplementedError | ||||||
return nil if @head == nil | ||||||
|
||||||
current = @head | ||||||
min = 0 | ||||||
|
min = 0 | |
min = current.data |
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.
👍
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.
👍
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.
👍
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.
Just noting this method isn't finished.
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.
👍
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.
👍
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.
👍
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.
👍 Good use of add_first
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.
👍
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.
👍