calc v1.0.0 Calculator
Basic idea: convert the infix expression to the postfix expression. Reference: https://leetcode.com/problems/basic-calculator-iii/discuss/113598/
Link to this section Summary
Functions
build the postfix list
build the postfix list when the head of current expression list is an operation, and the ops stack is not empty
Calculate using postfix
When the postfix is not empty, calculate using the top two elements in temp, and push the result to temp
Concat the digit that split apart
deal with the situation that first character is a
Main Evaluation function. Given an expression
Main function
When the operation stack is not empty, keep pushing the peek to postfix
If the string is a integer string, transform it to a integer. Otherwise return current str(operation)
Link to this section Functions
build the postfix list
build the postfix list when the head of current expression list is an operation, and the ops stack is not empty
Calculate using postfix
When the postfix is not empty, calculate using the top two elements in temp, and push the result to temp
Concat the digit that split apart
deal with the situation that first character is a
Main Evaluation function. Given an expression
remove all the space
return all the characters in the string as a list
as we will hit enter in the terminal and consider as a character, remove the enter.
Concat the integer string that split up
parse each character in the list
build a postfix list using current expression list, an empty postfix list and an empty stack
compute using postfix list
Main function.
When the operation stack is not empty, keep pushing the peek to postfix
If the string is a integer string, transform it to a integer. Otherwise return current str(operation)