Add [
, ]
as operators inside start and end of your string then:
Read numbers fill them in stack and read operators and do same, when you rich the operator which its value is lower or equal to previous operator in stack POP previous operator and act on the available numbers in numbers stack:
*:3, /:3, ):4, +:1,-:1
[12+34+4*56] ==>
Round 1: Numbers Stack: 12, Operator stack:[
Round 2: Numbers Stack: 12, Operator stack:[, +(1)
Round 3: Numbers Stack:12,34, Operator stack: [,+(1)
Round 4: Numbers Stack:12,34, Visited new operator with same or lower value (1) remove previous operator and pop 2 number from number stack and operate on them: So
Round 4: Numbers Stack:46, Operator stack: [,+(1)
Round 5: Numbers Stack:46,4 , Operator stack: [,+(1)
Round 6: Numbers Stack:46,4 , Operator stack: [,+(1),*(2)
Round 7: Numbers Stack:46,4,56, Operator stack: [,+(1),*(2)
Round 7: Numbers Stack:46,4,56, Operator stack: [,+(1),*(2) now operator item `]` want to be add, and it's priority is lower than all operators so operators sould be remove from stack and by each operator one number going to be removed:
Round 7: Numbers Stack:46,224 Operator stack: [,+(1),
Round 8: Numbers Stack:270 Operator stack: [,
Round 8: return 270, because ']' intered in Operator stack