-
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
Leaves-Yasmin #27
base: master
Are you sure you want to change the base?
Leaves-Yasmin #27
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.
Nice work. One minor issue with the Queue, but otherwise excellent job. Take a look at my comments and let me know if you have questions.
@store = Array.new(100) | ||
@front = @back = -1 | ||
# @front = -1 | ||
# @back = -1 | ||
end | ||
|
||
def enqueue(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.
👍
if element = @store[@front] | ||
@front = (@front + 1) % @store.length | ||
return 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.
The problem here is determining if the queue is empty or full because in either case front would be equal to back.
So
if element = @store[@front] | |
@front = (@front + 1) % @store.length | |
return element | |
if element = @store[@front] | |
@front = (@front + 1) % @store.length | |
@front = @back = -1 if @front == @back | |
return element |
end | ||
|
||
def size | ||
raise NotImplementedError, "Not yet implemented" | ||
# raise NotImplementedError, "Not yet implemented" | ||
return @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.
This only gives you the length of the internal storage, not the size of the queue.
if @front == @back | ||
return true | ||
else | ||
return false | ||
end |
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 @front == @back | |
return true | |
else | |
return false | |
end | |
return @front == @back |
return true | ||
else | ||
return false | ||
end | ||
end | ||
|
||
def to_s |
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.
👍
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation