Skip to content

Conversation

@MichaelWhalonCS
Copy link

No description provided.

Copy link

@GusPetito GusPetito left a comment

Choose a reason for hiding this comment

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

Hello! I looked over your code and left a few suggestions. You don't have to implement these and this doesn't affect your grades. They're just here for you to read over if you want to

def __init__(self, head=None):
self.head = head
self.length = 1
print(self.head)

Choose a reason for hiding this comment

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

It's probably best practice to remove unnecessary print statements before requesting to pull

Copy link
Author

Choose a reason for hiding this comment

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

Hey, I just saw these! Thank you for the feedback, these all help a lot.

class LinkList():
def __init__(self, head=None):
self.head = head
self.length = 1

Choose a reason for hiding this comment

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

Since head defaults to none, it's possible to start with a length of 0, so something with the ternary operator like:

Suggested change
self.length = 1
self.length = 0 if head == None else 1

may work

pass
self.length += 1
#for node in range(self.length-1)
node = self.head

Choose a reason for hiding this comment

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

Don't forget to check if self.head is None or not! Currently, making a LinkList with the default head value of None and adding to it would break the program, since you'd be calling None.next

def remove(self, data):
# write your code to REMOVE an element from the Linked List
pass
self.length -=1

Choose a reason for hiding this comment

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

Don't forget to check if the length is equal to 0! You don't want to be having a length of -1

Comment on lines +46 to +63
a = Node('a')
b = Node('b')
c = Node('c')
d = Node('d')

test = LinkList(a)
test.add(b)
test.add(c)
test.add(d)


print(test.head.value)
print(test.head.next.value)
print(test.head.next.next.value)
print(test.head.next.next.next.value)

print(test.get(c))
print('-'*25)

Choose a reason for hiding this comment

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

I like that you're testing out your LinkList, but it's best form to delete these before pull requesting, or at least putting them inside a if(name == 'main') statement so it doesn't run if someone wants to import your LinkList

Choose a reason for hiding this comment

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

Also, this type of testing is perfect for a separate unittest file, and ideally that's where it should be. But I understand if you were running out of time and just wanted a quick and dirty way to test.

Comment on lines +12 to +13
self.queue.pop(0)
self.length -= 1

Choose a reason for hiding this comment

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

Don't forget to check if the length is already 0!

Comment on lines +14 to +15
self.stack.pop(0)
self.length -= 1

Choose a reason for hiding this comment

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

Don't forget to check if self.length = 0!

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