-
Notifications
You must be signed in to change notification settings - Fork 48
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
Space - Stephanie #31
base: master
Are you sure you want to change the base?
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.
Overall very nice work, you hit the learning goals and some of the optionals. Well done.
# Time Complexity: O(1) bc it only adds one thing regardless of how big the list is | ||
# Space Complexity: O(1) | ||
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.
👍
if @head.nil? | ||
@head = Node.new(value) | ||
else | ||
@head = Node.new(value, @head) | ||
end |
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.
Could be simplified as:
if @head.nil? | |
@head = Node.new(value) | |
else | |
@head = Node.new(value, @head) | |
end | |
@head = Node.new(value, @head) |
# Time Complexity: O(n) because worst case it needs to run through all items in list | ||
# Space Complexity: O(1) | ||
def search(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.
👍
# 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 comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time Complexity: O(n) bc it has to run through every item | ||
# Space Complexity: O(1) | ||
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.
👍
# Time Complexity: O(n) bc it has to go thru every item on the list | ||
# Space Complexity: O(1) | ||
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.
👍
# Time Complexity: O(n) because you could look through entire list before you found specified value | ||
# Space Complexity: O(1) | ||
def delete(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.
👍
# Time Complexity: ? | ||
# Space Complexity: ? | ||
def get_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.
👍
# method that inserts a given value as a new last node in the linked list | ||
# Time Complexity: ? | ||
# Space Complexity: ? | ||
def add_last(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.
👍 , but time/space complexity?
# method that returns the value of the last node in the linked list | ||
# returns nil if the linked list is empty | ||
# Time Complexity: ? | ||
# Space Complexity: ? | ||
def get_last |
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.
👍 , but time/space complexity?
No description provided.