-
Notifications
You must be signed in to change notification settings - Fork 44
space katem #31
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
base: master
Are you sure you want to change the base?
space katem #31
Conversation
CheezItMan
left a comment
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 scope problems here which are causing the tests to give errors. You do seem to have the idea mostly down however. So I'd say you hit most of the learning goals here.
Take a look at my comments and let me know what questions you have.
| #create new stack array | ||
| stack_1 = Stack.new | ||
| #loop thorugh each character in the string | ||
| string.each_char do |char| |
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 the right idea here, but not quite there.
If the character is an open brace, parens etc. Push it into the Stack.
Otherwise pop the last item off the stack and see if it matches the current character, if it doesn't return false.
Continue until the end of the string.
| #helper function here | ||
| #when you pop, make sure to set it to int | ||
| def pop_two_jenga_pieces | ||
| value1 = jenga_stack.pop.to_i |
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.
jenga?
| operands = { "0" => 0, "1" => 1, "2" => 2, "3" => 3, "4" => 4, "5" => 5, "6" => 6, "7" => 7, "8" => 8, "9" => 9 } | ||
| #helper function here | ||
| #when you pop, make sure to set it to int | ||
| def pop_two_jenga_pieces |
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.
👍
| #loop through the expression | ||
| postfix_expression.each_char do |char| | ||
| #check if operands are included | ||
| if operands.include?(char) |
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 should make operands a constant so it has global scope. This is failing because this method doesn't have a local variable named operands.
| end | ||
|
|
||
| #example: i want to add myself to a line of 20 people for coffee | ||
| 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.
👍
| @@ -1,31 +1,102 @@ | |||
| class Queue | |||
| # set queue_size here to something like 20 or whatever | |||
| queue_size = 20 | |||
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 should be a constant, the fact that it's not gives you scope problems and failing tests
| return @front | ||
| end | ||
|
|
||
| def size |
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 can use the positions of front and rear to calculate the size of the queue.
| @@ -1,19 +1,27 @@ | |||
| class Stack | |||
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