-
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
Branches - Kelsey #25
base: master
Are you sure you want to change the base?
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.
Some issues with the Queue class. Take a look at my comments and let me know if you have any questions. The other parts seem to work well.
# Time Complexity: O(n) | ||
# Space Complexity: O(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.
👍
if stack.empty? | ||
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 stack.empty? | |
return true | |
else | |
return false | |
end | |
return stack.empty? |
# remove dequeued item from queue | ||
@store[@front] = nil | ||
# move front to next item in queue | ||
@front = @front+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.
You need to make sure the front will wrap around the queue
@front = @front+1 | |
@front = (@front+1) % @store.length |
You also need to check to see if the queue is empty!
def size | ||
raise NotImplementedError, "Not yet implemented" | ||
return @store.compact.length | ||
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.
This works, but it's not very efficient.
def to_s | ||
@store.compact! |
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 compacts the buffer which removes any extra space you have in the buffer, which you might need in the Queue!
Better to do something like this:
return "[]" if @front == -1
current = @front
output = "["
next = (@front + 1) % @store.length
while next != @back
output += "#{@store[current]},"
current = (current + 1) % @store.length
next = (next + 1) % @store.length
end
output += "#{@store[current]}]"
return output
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation