-
Notifications
You must be signed in to change notification settings - Fork 13
Jason and Michael Data Structures #1
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
GusPetito
left a comment
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.
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) |
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.
It's probably best practice to remove unnecessary print statements before requesting to pull
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.
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 |
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.
Since head defaults to none, it's possible to start with a length of 0, so something with the ternary operator like:
| 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 |
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.
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 |
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.
Don't forget to check if the length is equal to 0! You don't want to be having a length of -1
| 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) |
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.
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
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.
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.
| self.queue.pop(0) | ||
| self.length -= 1 |
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.
Don't forget to check if the length is already 0!
| self.stack.pop(0) | ||
| self.length -= 1 |
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.
Don't forget to check if self.length = 0!
No description provided.