-
Notifications
You must be signed in to change notification settings - Fork 86
C16 Cedar LinkedLists #60
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
@@ -1,75 +1,136 @@ | |||
|
|||
# Defines a node in the singly linked list | |||
class Node: | |||
from platform import node |
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.
where is this coming from? You've created your own Node
class on line 6, so you don't need to import a third-party class
|
||
class Node: |
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 Complexity: ? | ||
# Time Complexity: O(1) | ||
# Space Complexity: O(1) | ||
|
||
def get_first(self): |
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: ? | ||
# Time Complexity: O(1) | ||
# Space Complexity: O(1) | ||
def add_first(self, 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: ? | ||
# Time Complexity: O(n) | ||
# Space Complexity: O(1) | ||
def search(self, 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.
👍
current = self.head | ||
current = self.head |
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 have this twice
current = self.head | |
current = self.head | |
current = self.head |
|
||
current = self.head | ||
current = self.head | ||
while current.next is not None: |
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.
while current.next is not None: | |
while current.next: |
if value == current.next.value: | ||
break | ||
current = current.next | ||
if current.next is None: | ||
print("Node not found") | ||
else: | ||
current.next = current.next.next |
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.
There's a couple if statements here that aren't really doing anything but stop the loop or print. It makes it hard to read what is important here. I think we can shorten it:
if value == current.next.value: | |
break | |
current = current.next | |
if current.next is None: | |
print("Node not found") | |
else: | |
current.next = current.next.next | |
if value == current.next.value: | |
current.next = current.next.next | |
current = current.next |
Since there could be more than one node with the same value, we don't want to break
pass | ||
prev = None | ||
current = self.head | ||
while current is not None: |
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.
while current is not None: | |
while current: |
# Time Complexity: ? | ||
# Space Complexity: ? |
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.
What do you think the space and time complexity of this is? Is the time complexity dependent on the length of the linked list? Is there any new variables being created that grow larger depending upon the input?
No description provided.