Tiffany C.#34
Open
TiffanyChio wants to merge 3 commits into
Open
Conversation
CheezItMan
reviewed
Mar 10, 2020
CheezItMan
left a comment
There was a problem hiding this comment.
Nicely done, some small issues with Queue. Take a look at my comments, but you hit all the major learning goals here.
| # 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.
This works, but you can make it simpler by using a hash to do the mashing instead of using the case statement.
| # Space Complexity: ? | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def evaluate_postfix(postfix_expression) |
| class Queue | ||
| require_relative './linked_list' | ||
|
|
||
| class Queue |
There was a problem hiding this comment.
| def initialize | ||
| @store = Array.new(30) | ||
| @front = @back = 0 | ||
| # full when front == back |
There was a problem hiding this comment.
But when this object is created they're both equal!
| @back = (@back + 1) % @store.length | ||
| end | ||
|
|
||
| def dequeue |
| # full when front == back | ||
| end | ||
|
|
||
| def enqueue(element) |
Comment on lines
+35
to
+41
| def front | ||
| raise NotImplementedError, "Not yet implemented" | ||
| end | ||
|
|
||
| def size | ||
| raise NotImplementedError, "Not yet implemented" | ||
| end |
Comment on lines
+47
to
+49
| def to_s | ||
| return @store.compact.to_s | ||
| end |
There was a problem hiding this comment.
This works but it doesn't preserve element order if the back has wrapped around the buffer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation