-
Notifications
You must be signed in to change notification settings - Fork 42
Niv #19
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?
Niv #19
Conversation
CheezItMan
left a comment
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.
You hit most of the learning goals here. In particular you didn't use a circular buffer to implement a Queue. See my notes. Let me know if you want help with this.
|
|
||
| def balanced(string) | ||
| raise NotImplementedError, "Not implemented yet" | ||
| pairs = {")" => "(", "}" => "{", "]"=>"["} |
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.
Great use of a hash!
lib/queue.rb
Outdated
|
|
||
| def enqueue(element) | ||
| raise NotImplementedError, "Not yet implemented" | ||
| @store.push(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.
This isn't using a circular buffer, it works, but not what I requested.
lib/queue.rb
Outdated
| def dequeue | ||
| raise NotImplementedError, "Not yet implemented" | ||
| removed = @store[0] | ||
| @store = @store[1..-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.
Just a note, dequeue is an O(n) operation because of how you're using the array here.
CheezItMan
left a comment
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 mostly good, a few bugs here and there. I've added some tests for next cohort to help catch them. Take a look at my comments and let me know if you have questions.
|
|
||
| def enqueue(element) | ||
| raise NotImplementedError, "Not yet implemented" | ||
| if @front == 0 && @rear == @BUFFER_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.
This could run into trouble if the Queue becomes full and the front is not at index 0.
Consider if you had a buffer size of 10,
You add 9 elements, remove one (so front is at index 1) and then try to add 7 more. What happens?
|
|
||
| def dequeue | ||
| raise NotImplementedError, "Not yet implemented" | ||
| removed_data = @store[@front] |
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.
Before dequeuing you should check to see if the queue is empty.
| if (@front == @rear) | ||
| @front = -1 | ||
| @rear = -1 | ||
| elsif @front === @BUFFER_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.
This kind of elsif statements work or you could do: @front = (@front + 1) % BUFFER_SIZE
| display_store = @store[@front...@rear+1] | ||
| else | ||
| first_half = @store[0...@rear] | ||
| second_half = @store[@front..@store.length+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.
I don't think this actually works.
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation