-
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
Tiffany C. #34
base: master
Are you sure you want to change the base?
Tiffany C. #34
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.
Nicely done, some small issues with Queue. Take a look at my comments, but you hit all the major learning goals here.
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(n), push and pop should be O(1) operations since the linked list has both a head and tail pointer | ||
# Space Complexity: O(n) if the string is not balanced and comprised wholly of open brackets, also O(n) if it actually closes | ||
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.
This works, but you can make it simpler by using a hash to do the mashing instead of using the case statement.
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(n) | ||
# Space Complexity: O(n) | ||
def evaluate_postfix(postfix_expression) |
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.
👍
|
||
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.
def initialize | ||
@store = Array.new(30) | ||
@front = @back = 0 | ||
# full when front == back |
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.
But when this object is created they're both equal!
@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.
👍
# full when front == back | ||
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.
👍
def front | ||
raise NotImplementedError, "Not yet implemented" | ||
end | ||
|
||
def size | ||
raise NotImplementedError, "Not yet implemented" | ||
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.
So not all done
def to_s | ||
return @store.compact.to_s | ||
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 doesn't preserve element order if the back has wrapped around the buffer.
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation