-
Notifications
You must be signed in to change notification settings - Fork 63
Shaina Beth C16 Spruce #47
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
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.
✨🌸 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨ 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. |
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.
✨
|
||
return to_ret | ||
|
||
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.
✨
return self.store[self.front] | ||
|
||
|
||
def size(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.
✨
""" 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. |
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.
✨
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.
✨
v = self.store.get_first() | ||
self.store.remove_first() | ||
return v |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨ 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨ 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