-
Notifications
You must be signed in to change notification settings - Fork 178
Rachael: The slowest moving Water (class) #7
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?
Changes from all 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 |
|---|---|---|
|
|
@@ -10,36 +10,81 @@ def initialize | |
| # Time complexity - ? | ||
| # Space complexity - ? | ||
| def add_first(data) | ||
|
|
||
| new_node = Node.new(data) | ||
| new_node.next = @head | ||
| @head = new_node | ||
| return @head.data | ||
| end | ||
|
|
||
| # Time complexity - ? | ||
| # Space complexity - ? | ||
| def get_first | ||
|
Comment on lines
19
to
21
Contributor
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. 👍 Space/Time Complexity? |
||
|
|
||
| if @head | ||
| return @head.data | ||
| end | ||
| return nil | ||
| end | ||
|
|
||
| # Time complexity - ? | ||
| # Space complexity - ? | ||
| def length | ||
|
Comment on lines
28
to
30
Contributor
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. 👍 Space/Time Complexity? |
||
| return 0 | ||
| count = 0 | ||
| current = @head | ||
| while current != nil | ||
| count += 1 | ||
| current = current.next | ||
| end | ||
|
|
||
| return count | ||
| end | ||
|
|
||
| # Time complexity - ? | ||
| # Space complexity - ? | ||
| def add_last(data) | ||
|
Comment on lines
41
to
43
Contributor
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. 👍 Space/Time Complexity? |
||
|
|
||
| current = @head | ||
| if @head == nil | ||
| current = Node.new(data) | ||
| @head = current | ||
| return | ||
| end | ||
| until current == nil | ||
| previous = current | ||
| current = current.next | ||
| end | ||
| previous.next = Node.new(data) | ||
| return | ||
| end | ||
|
|
||
| # Time complexity - ? | ||
| # Space complexity - ? | ||
| def get_last | ||
|
Comment on lines
58
to
60
Contributor
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. 👍 Space/Time Complexity? |
||
| current = @head | ||
| if @head == nil | ||
| return nil | ||
| end | ||
| until current == nil | ||
| previous = current | ||
| current = current.next | ||
| end | ||
| return previous.data | ||
|
|
||
| end | ||
|
|
||
| # Time complexity - ? | ||
| # Space complexity - ? | ||
| def get_at_index(index) | ||
|
Comment on lines
73
to
75
Contributor
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. 👍 Space/Time Complexity? |
||
|
|
||
| count = 0 | ||
| current = @head | ||
| if @head == nil | ||
| return nil | ||
| end | ||
| until count == index | ||
| count += 1 | ||
| current = current.next | ||
| end | ||
| if current == nil | ||
| return nil | ||
| end | ||
| return current.data | ||
| end | ||
| 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.
👍 Space/Time Complexity?