-
Notifications
You must be signed in to change notification settings - Fork 44
Charlotte:Space #35
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?
Charlotte:Space #35
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 | |||
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.
👍
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.
Better, you have most of the circular buffer now. Well done.
| elsif @store.empty? | ||
| raise ArgumentError, "Full" |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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