Postfix Expression Evaluator

Stack Postfix Evaluation

Description

In this exercise, you'll implement a function that evaluates a mathematical expression written in postfix notation (also known as Reverse Polish Notation). In a postfix expression, every operator follows all of its operands. For example, the postfix expression 3 4 + 2 * is evaluated as:

  1. Add 3 and 4 to get 7.
  2. Multiply 7 by 2 to get 14.

Your task is to parse the given string (where tokens are separated by spaces) and return the evaluated result as a number.

Input: A string containing a valid postfix expression consisting of non-negative integers and the operators +, -, *, /.

Output: A number representing the result of the evaluated expression.

Note: Division should be treated as integer division if your language does not automatically use floating-point arithmetic where appropriate.

Fun Fact: On March 11th, we celebrate creativity and innovation. Use your stack skills to build an innovative solution!

Example

For the input: "5 1 2 + 4 * + 3 -", the function should return 14.

Starter Code

Below you will find starter code snippets in multiple languages to help you begin your solution.