-
Notifications
You must be signed in to change notification settings - Fork 48
Yaz - Linked List #44
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?
Conversation
…tead of tring to assign a list to a node
CheezItMan
left a comment
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.
Nice work Yaz, thanks for getting this in. The methods you implementing are pretty well done. You did miss some entries for time/space complexity. Otherwise excellent work.
| # 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 | ||
| # Time Complexity: O(1) | ||
| # 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 | ||
| second = @head | ||
| @head = Node.new(value, second) | ||
| else | ||
| @head = Node.new(value) | ||
| 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.
| if @head | |
| second = @head | |
| @head = Node.new(value, second) | |
| else | |
| @head = Node.new(value) | |
| end | |
| @head = Node.new(value, @head) |
| # Time Complexity: O(n) | ||
| # 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.
👍 Nice helper method
| # 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) | ||
| # 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.
👍
| # method to delete the first node found with specified value | ||
| # Time Complexity: O(n) | ||
| # 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.
👍
| # method to reverse the singly linked list | ||
| # note: the nodes should be moved and not just the values in the nodes | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| 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.
👍
| ## Advanced Exercises | ||
| # returns the value at the middle element in the singly linked list | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def find_middle_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: O(n) | ||
| # Space Complexity: O(1) | ||
| def find_nth_from_end(n) |
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.
👍
No description provided.