Task: evaluate postfix expression given as int tokens and ops codes. Use stack.
First line: Integer n (number of tokens)
Second line: n space-separated tokens (integers and operators)
Operators can be: +, -, *, /
Print one integer: the result of the postfix expression
• 1 ≤ n ≤ 100
• Tokens are valid integers or operators
• Division is integer division
• The postfix expression is valid
Postfix expression: 2 3 1 * +
Step-by-step evaluation:
• Push 2
• Push 3
• Push 1
• * → 3 × 1 = 3 → push 3
• + → 2 + 3 = 5
Final result = 5
1.Create a Stack.
2.Traverse all tokens.
3.If token is a number → push into stack.
4.If token is an operator:
• Pop two numbers from stack (operand2 and operand1).
• Perform operation: operand1 operator operand2.
• Push result back to stack.
5.After processing all tokens, the stack will contain one value.
6.Print that value.