Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

rebecamuniz
Copy link

No description provided.

@@ -1,75 +1,136 @@

# Defines a node in the singly linked list
class Node:
from platform import node

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:

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):

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):

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):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +124 to +125
current = self.head
current = self.head

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have this twice

Suggested change
current = self.head
current = self.head
current = self.head


current = self.head
current = self.head
while current.next is not None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
while current.next is not None:
while current.next:

Comment on lines +127 to +133
if value == current.next.value:
break
current = current.next
if current.next is None:
print("Node not found")
else:
current.next = current.next.next

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:

Suggested change
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:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
while current is not None:
while current:

Comment on lines 150 to 151
# Time Complexity: ?
# Space Complexity: ?

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants