Created
March 7, 2018 13:14
-
-
Save kmdsbng/b08f57904d7342ca815e59f279cd93ed to your computer and use it in GitHub Desktop.
This file contains 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
class Calculator { | |
val stack = mutableListOf<Int>() | |
fun pushOperand(operand: Int) { | |
stack.add(operand) | |
} | |
fun pushOperator(operand: String) { | |
when(operand) { | |
"+" -> { | |
val right = stack.removeAt(stack.count() - 1) | |
val left = stack.removeAt(stack.count() - 1) | |
stack.add(right + left) | |
} | |
} | |
} | |
fun getResult(): Int { | |
return stack.last() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment