-
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 - Emily Ball #39
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.
You have some minor issues with Queue, but otherwise this is very well done. Nice work! You hit all the major learning goals here. Well done.
# Time Complexity: O(n) where n is characters in string | ||
# Space Complexity: O(n) where n is characters in string | ||
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.
👍
@size = 20 | ||
@store = Array.new(@size) | ||
@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.
👍
end | ||
|
||
@store[@back] = element | ||
@back = (@back + 1) % @store.length | ||
end | ||
|
||
def dequeue |
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.
👍
end | ||
|
||
def front | ||
raise NotImplementedError, "Not yet implemented" | ||
return nil if empty? | ||
return @front |
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 @front | |
return @stores[@front] |
return @front - @back if @front > @back | ||
return @back + (@store.length - @front) |
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 think you have this reversed here.
return @front - @back if @front > @back | |
return @back + (@store.length - @front) | |
return @back - @front if @front < @back | |
return @back + (@store.length - @front) |
end | ||
|
||
def empty? | ||
raise NotImplementedError, "Not yet implemented" | ||
@front == -1 && @back == -1 | ||
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.
👍 This works, but you could do it with just a single loop like while i != @back
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation