-
Notifications
You must be signed in to change notification settings - Fork 61
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
Dani Sanchez - Paper #35
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.
Really nice work Dani, this works well. I left a little commentary on small things, but overall a solid submission.
if self.size == self.buffer_size: | ||
raise QueueFullException() | ||
|
||
|
||
self.rear = (self.rear + 1) % self.buffer_size | ||
self.store[self.rear] = element | ||
self.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.
👍
|
||
return_value = self.store[self.front] | ||
self.store[self.front] = None | ||
self.front += 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.
One correction
self.front += 1 | |
self.front = (self.front + 1) % self.buffer_size |
if self.rear < self.front: | ||
items_str = ", ".join(str(self.store[item]) for item in range(self.front, self.size - 1)) | ||
second_set_items = ", ".join(str(self.store[item]) for item in range(-1, self.rear + 1)) | ||
joined_items = "[" + items_str + ", " + second_set_items + "]" | ||
return joined_items | ||
|
||
else: | ||
items_str = ", ".join(str(self.store[item]) for item in range(self.front, self.rear + 1)) | ||
joined_items = "[" + items_str + "]" | ||
return joined_items |
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.
This is a little overcomplicated. You could instead start an index at self.front
, and change it by current_index = (current_index + 1) % self.buffer_size
adding each item to your output until you reach self.rear
@@ -12,7 +12,8 @@ def push(self, element): | |||
""" Adds an element to the top of the Stack. |
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.
The stack looks good!
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation