-
Notifications
You must be signed in to change notification settings - Fork 49
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
Janice H. #32
base: master
Are you sure you want to change the base?
Janice H. #32
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.
Overall not bad, but you have some issues and unfinished methods in Queue. I also suggest you not use puts unless the method's purpose is output. Instead raise an error or return a meaningful value.
Take a look at my comments and let me know any questions.
@store[@back-1] = element | ||
@back = (@back + 1) % @store.length # to get back to index 0 |
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're having to do @back-1
because you have set @back
to 1 in the first if in this method and you wrote two separate ifs. Converting if @front == @back
into an elsif would make this a bit more straightforward.
def dequeue | ||
raise NotImplementedError, "Not yet implemented" | ||
if @front == -1 && @back == -1 | ||
puts 'queue is empty, sorry!' |
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 would raise an error here instead of puts.
return | ||
end | ||
value = @store[@front] | ||
@front = (@front + 1) % @store.length |
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 also need to check if the queue is now empty here.
def empty? | ||
raise NotImplementedError, "Not yet implemented" | ||
return true if @front == -1 && @back == -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 true if @front == -1 && @back == -1 | |
return @front == -1 && @back == -1 |
Chris--Sorry, I didn't have much time this week and didn't quite finish this assignment. I will try to do more in the next few days and push any changes, but I thought it would be better to first submit what I have. Thanks.
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation