Conversation
There was a problem hiding this comment.
✨🌸 Nice work! I left a few comments making some recommendations for how you might refactor your code, but it looks like you understand queues with a circular buffer and stacks with linked lists. Let me know what questions you have.
For the comprehension questions, I would note that when adding/removing items from a Stack you do not necessarily have to append/remove from the front of an array - rather you must always append and remove from the same side. For implementing vs using, you are mostly correct. However, I want to clarify that using the code could also be using a library or calling a function someone else wrote; you don't need to necessarily run a program with that code.
🟢
| returns None | ||
| """ | ||
| pass | ||
| if self.size == INITIAL_QUEUE_SIZE: |
There was a problem hiding this comment.
I would suggest comparing to buffer_size instead of your constant. That way, if you were ever to expand or adapt this class to have a buffer size that could increase or decrease, you code would still work without needing to change all references to INITIAL_QUEUE_SIZE to the new buffer size.
| if self.size == INITIAL_QUEUE_SIZE: | |
| if self.size == self.buffer_size: |
| """ Adds an element to the Queue | ||
| Raises a QueueFullException if all elements | ||
| In the store are occupied | ||
| returns None |
There was a problem hiding this comment.
✨ However, see my comment regarding your use of INITIAL_QUEUE_SIZE below ⬇️
| def dequeue(self): | ||
| """ Removes and returns an element from the Queue | ||
| Raises a QueueEmptyException if | ||
| The Queue is empty. |
|
|
||
| return to_ret | ||
|
|
||
| def front(self): |
| return self.store[self.front] | ||
|
|
||
|
|
||
| def size(self): |
| """ Returns the Queue in String form like: | ||
| [3, 4, 7] | ||
| Starting with the front of the Queue and | ||
| ending with the rear of the Queue. |
| Returns None | ||
| """ | ||
| pass | ||
| self.store.add_first(element) |
| v = self.store.get_first() | ||
| self.store.remove_first() | ||
| return v |
There was a problem hiding this comment.
If you read the docstrings of the LinkedList class, you'll see that remove_first returns the value of the node it removes.
| v = self.store.get_first() | |
| self.store.remove_first() | |
| return v | |
| return self.store.remove_first() |
| self.store.remove_first() | ||
| return v | ||
|
|
||
| def empty(self): |
There was a problem hiding this comment.
✨ Alternatively, you could take advantage of the LinkedList class' empty method
| pass | ||
| return self.store.get_first() == None | ||
|
|
||
| def __str__(self): |
There was a problem hiding this comment.
✨ Alternatively, you could take advantage of the LinkedList class' str method
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation