Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
You hit many of the learning goals here. However the Queue wasn't implemented with a circular buffer... which was the meat of the assignment.
Other than that things look good.
lib/problems.rb
Outdated
| # Time Complexity: 0(n) where n is the length | ||
| # Space Complexity: 0(n) | ||
| def balanced(string) |
There was a problem hiding this comment.
Did you know that you can use a hash here where the keys are the open parens and the values are the matching close braces. That way you can quickly check to see if they match.
This does work however.
lib/queue.rb
Outdated
| raise NotImplementedError, "Not yet implemented" | ||
| def initialize(size=20) | ||
| @size = size | ||
| @store = Array.new() |
There was a problem hiding this comment.
You should probably start the array at the given size
| @store = Array.new() | |
| @store = Array.new(size) |
| @@ -1,28 +1,37 @@ | |||
| class Queue | |||
There was a problem hiding this comment.
This works, but it's not what was asked. The assignment calls you to create a Queue using a circular buffer. So... yes it's a queue and passes the tests, but it wasn't implemented as requested.
| @@ -1,19 +1,22 @@ | |||
| class Stack | |||
CheezItMan
left a comment
There was a problem hiding this comment.
Better, you have most of the circular buffer now. Well done.
| elsif @store.empty? | ||
| raise ArgumentError, "Full" |
There was a problem hiding this comment.
If the Queue is empty raise an argument error that it's full?
I think you want to check to see if it's full by doing if (@back + 1) % @store.length == @front
| else | ||
| data = @store[@front] | ||
| @front = (@front + 1) % @size | ||
| if @store.empty? |
There was a problem hiding this comment.
You already checked to see if it's empty above with if @front == -1
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation