-
Notifications
You must be signed in to change notification settings - Fork 419
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
Spruce - Michelle Morales #15
base: master
Are you sure you want to change the base?
Conversation
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.
🤠💫 Very solid implementation, Michelle! Make sure you fork against the C16 version instead of AdaGold next time! Let me know what questions you have.
🟢
self.size = 0 | ||
|
||
|
||
def enqueue(self, element): |
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.
✨
|
||
self.store[self.rear] = element | ||
self.rear = (self.rear + 1) % self.buffer_size | ||
self.size += 1 | ||
|
||
def dequeue(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.
✨
if self.front == self.rear: | ||
self.front = -1 | ||
self.rear = -1 | ||
return value | ||
|
||
def front(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.
✨
@@ -13,49 +13,78 @@ def __init__(self): | |||
self.store = [None] * INITIAL_QUEUE_SIZE | |||
self.buffer_size = INITIAL_QUEUE_SIZE | |||
self.front = -1 | |||
self.rear = -1 | |||
self.rear = 0 |
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 not really anything wrong with initializing this to 0, but since you reset it to '-1' in dequeue
below when the queue becomes empty, it's best to stay consistent across the board.
self.rear = 0 | |
self.rear = -1 |
if self.front == -1: | ||
return 0 | ||
return self.size |
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 size
should already be 0 if the queue is empty, you can probably delete lines 65 - 66.
if self.front == -1: | |
return 0 | |
return self.size | |
return self.size |
for x in range(size): | ||
result.append(self.store[index]) | ||
index = (index + 1) % self.buffer_size | ||
size -= 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.
We generally try not to change the value we are iterating through, and it's not necessary to modify size here.
size -= 1 |
@@ -12,7 +12,7 @@ def push(self, element): | |||
""" Adds an element to the top of the Stack. | |||
Returns None | |||
""" | |||
pass | |||
self.store.add_first(element) |
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.
✨
@@ -21,18 +21,18 @@ def pop(self): | |||
The Stack is empty. | |||
returns None | |||
""" | |||
pass | |||
return self.store.remove_first() |
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.
✨
|
||
def empty(self): | ||
""" Returns True if the Stack is empty | ||
And False otherwise | ||
""" | ||
pass | ||
return self.store.empty() |
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.
✨
|
||
def __str__(self): | ||
""" Returns the Stack in String form like: | ||
[3, 4, 7] | ||
Starting with the top of the Stack and | ||
ending with the bottom of the Stack. | ||
""" | ||
pass | ||
return str(self.store) |
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.
✨
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation