Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
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.
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 |
| 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 |
| #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.
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) |
| @@ -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.
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.
You can use the positions of front and rear to calculate the size of the queue.
| @@ -1,19 +1,27 @@ | |||
| class Stack | |||
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation