Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
Not bad, you hit most of the learning goals. In particular see my notes on your Stack implementation. Let me know if you have questions.
| else | ||
| dequeued = @store[@front] | ||
| @store[@front] = nil | ||
| @front = (@front + 1) % QUEUE_SIZE |
There was a problem hiding this comment.
You should also check to see if the queue is now empty.
|
|
||
| def empty? | ||
| raise NotImplementedError, "Not yet implemented" | ||
| queue = @store.compact |
There was a problem hiding this comment.
This is a pretty expensive way to see if the queue is empty.
Why not just return @front == -1?
|
|
||
| def size | ||
| raise NotImplementedError, "Not yet implemented" | ||
| return @store.compact.length |
There was a problem hiding this comment.
This is a bit expensive. You could also calculate the size based on the locations of front and rear.
|
|
||
| def push(element) | ||
| raise NotImplementedError, "Not yet implemented" | ||
| if @front == -1 |
There was a problem hiding this comment.
You don't really need a circular buffer for a Stack as you only add or remove on one end (the top). Instead I'd asked you to use a Linked List. So this is a little weird.
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation