Skip to content

Instantly share code, notes, and snippets.

@kmdsbng
Created March 7, 2018 13:14
Show Gist options
  • Save kmdsbng/b08f57904d7342ca815e59f279cd93ed to your computer and use it in GitHub Desktop.
Save kmdsbng/b08f57904d7342ca815e59f279cd93ed to your computer and use it in GitHub Desktop.
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