-
Notifications
You must be signed in to change notification settings - Fork 48
Yieni-Space #30
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?
Yieni-Space #30
Changes from all commits
16967c1
f54168e
a36eb26
125c128
769ef27
4319b49
7ad28b3
47cb0ec
1485b35
2183b49
90429f4
28ffc08
dcd8971
c717fd8
83fcfed
e0e120a
a2022a8
d292664
6b15809
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 |
|---|---|---|
|
|
@@ -18,40 +18,70 @@ 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 | ||
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| # Time Complexity: O(1)? | ||
| # Space Complexity: O(1)? | ||
| 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 | ||
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| # Time Complexity: o(n)? | ||
| # Space Complexity: O(1)? | ||
| def search(value) | ||
|
Comment on lines
+31
to
33
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 false if @head == nil | ||
| current = @head | ||
|
|
||
| until current == nil | ||
| 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 | ||
|
Comment on lines
44
to
46
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 | ||
|
|
||
| max = @head | ||
| current = @head | ||
|
|
||
| until current == nil | ||
| current.data > max.data ? max = current : 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 | ||
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| # Time Complexity: O(n)? | ||
| # Space Complexity: O(1)? | ||
| def find_min | ||
|
Comment on lines
+60
to
62
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 | ||
| min = @head | ||
| current = @head | ||
|
|
||
| until current == nil | ||
| current.data < min.data ? min = current : current = current.next | ||
| end | ||
| return min.data | ||
| end | ||
|
|
||
|
|
||
| # method that returns the length of the singly linked list | ||
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| def length | ||
|
Comment on lines
75
to
77
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. 👍 , time/space complexity ❓ |
||
| raise NotImplementedError | ||
| count = 0 | ||
| current = @head | ||
| until current == nil | ||
| count += 1 | ||
| current = current.next | ||
| end | ||
| return count | ||
| end | ||
|
|
||
| # method that returns the value at a given index in the linked list | ||
|
|
@@ -60,29 +90,40 @@ def length | |
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| def get_at_index(index) | ||
|
Comment on lines
90
to
92
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. 👍 With one caveat below |
||
| raise NotImplementedError | ||
| return nil if @head.nil? | ||
|
|
||
| current = @head | ||
| index.times do | ||
| current = current.next | ||
| end | ||
|
Comment on lines
+96
to
+98
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. What if |
||
| return current.data | ||
| end | ||
|
|
||
| # method to print all the values in the linked list | ||
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| def visit | ||
|
Comment on lines
103
to
105
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. 👍 Time/space complexity ❓ |
||
| raise NotImplementedError | ||
| current = @head | ||
|
|
||
| until current == nil | ||
| puts current.data | ||
| current = current.next | ||
| end | ||
| end | ||
|
|
||
| # method to delete the first node found with specified value | ||
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| def delete(value) | ||
| raise NotImplementedError | ||
|
|
||
| end | ||
|
|
||
| # method to reverse the singly linked list | ||
| # note: the nodes should be moved and not just the values in the nodes | ||
| # Time Complexity: ? | ||
| # Space Complexity: ? | ||
| def reverse | ||
| raise NotImplementedError | ||
|
|
||
| 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.
👍 , very compact!