forked from AdaGold/linked-list
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Kate N #26
Open
KateAnnNichols
wants to merge
1
commit into
Ada-C11:master
Choose a base branch
from
KateAnnNichols:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Kate N #26
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,42 +18,44 @@ 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) | ||
# o(1) b/c pointers at head + tail | ||
def add_first(value) | ||
raise NotImplementedError | ||
node = Node.new data | ||
self.length +=1 | ||
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(n) | ||
def search(value) | ||
raise NotImplementedError | ||
return value unless | ||
end | ||
|
||
# method to return the max value in the linked list | ||
# returns the data value and not the node | ||
# Time Complexity: | ||
# Space Complexity | ||
def find_max | ||
raise NotImplementedError | ||
|
||
end | ||
|
||
# method to return the min value in the linked list | ||
# returns the data value and not the node | ||
# Time Complexity: | ||
# Space Complexity | ||
def find_min | ||
raise NotImplementedError | ||
|
||
end | ||
|
||
|
||
# method that returns the length of the singly linked list | ||
# Time Complexity: | ||
# Space Complexity | ||
def length | ||
raise NotImplementedError | ||
|
||
end | ||
|
||
# method that returns the value at a given index in the linked list | ||
|
@@ -62,29 +64,43 @@ def length | |
# Time Complexity: | ||
# Space Complexity | ||
def get_at_index(index) | ||
raise NotImplementedError | ||
current_node = @head | ||
while current_node.next? | ||
current_node = current_node.next | ||
end | ||
|
||
# method to print all the values in the linked list | ||
# Time Complexity: | ||
# Space Complexity | ||
def visit | ||
raise NotImplementedError | ||
|
||
end | ||
|
||
# method to delete the first node found with specified value | ||
# Time Complexity: | ||
# Space Complexity | ||
#### method to delete the first node found with specified value | ||
# Time Complexity: o(n) | ||
# Space Complexity: o(n) | ||
def delete(value) | ||
raise NotImplementedError | ||
if self.value = true | ||
remove self | ||
end | ||
|
||
# method to reverse the singly linked list | ||
#### 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 | ||
# Space Complexity: | ||
# do with + w/o recursion ? | ||
def reverse | ||
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. 👍 Since you didn't make any external data structures, your space complexity here is O(1), and since you have to traverse the list once, your time complexity is O(n). You can usually guess this by the fact that there is one and only one loop. |
||
raise NotImplementedError | ||
current_node = @head | ||
previous_node = nil | ||
next_node = nil | ||
|
||
while current_node | ||
next_node = current_node.pointer | ||
current_node.set_pointer(previous_node) | ||
previous_node = current_node | ||
current_node = next_node | ||
end | ||
@head = previous_node | ||
end | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You're not changing
@head
at all.