Jesse Pope - CS Fun Stacks and Queues#31
Conversation
kyra-patton
left a comment
There was a problem hiding this comment.
✨🤠 Nice work! I left a few comments regarding how we can tell if the queue is empty, but otherwise solid implementation. Let me know what questions you have.
🟢
|
|
||
|
|
||
| def enqueue(self, element): |
| self.size += 1 | ||
|
|
||
|
|
||
| def dequeue(self): |
There was a problem hiding this comment.
✨ This is all correct, however consider the case that you remove the last element in the queue. You may want to redirect your front and rear pointers to point at -1 as an indication the queue is empty.
|
|
||
| return front | ||
|
|
||
| def front(self): |
There was a problem hiding this comment.
The rear and front pointers being equal does indicate the queue is empty, however it could also be an indication the queue is full... how else might we consider the queue being empty?
| return self.store[self.front] | ||
|
|
||
|
|
||
| def size(self): |
| pass | ||
| return self.size | ||
|
|
||
| def empty(self): |
There was a problem hiding this comment.
👀 Same thing as your front method with self.front and self.rear being equal. Consider using self.size or think about what values self.front and self.rear will both have if the queue is empty.
However, your overall logic is correct!
| else: | ||
| return False | ||
|
|
||
| def __str__(self): |
| Returns None | ||
| """ | ||
| pass | ||
| self.store.add_first(element) |
| returns None | ||
| """ | ||
| pass | ||
| return self.store.remove_first() |
| And False otherwise | ||
| """ | ||
| pass | ||
| return self.store.empty() |
| ending with the bottom of the Stack. | ||
| """ | ||
| pass | ||
| return str(self.store) |
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation