### Example 8: `((A + B) * C) ^ D - E`


| Token (Input) | Action                                                                  | Operator Stack (Top Right) | Postfix Output        | Notes                                                                                                  |
| :------------ | :---------------------------------------------------------------------- | :------------------------- | :-------------------- | :----------------------------------------------------------------------------------------------------- |
| `(`           | Open Paren (`op1`): Push `(`.                                           | `[(`                       |                       | Outer parenthesis for `^` base                                                                         |
| `(`           | Open Paren (`op2`): Push `(`.                                           | `[(, (`                   |                       | Inner parenthesis for `A+B`                                                                            |
| `A`           | Operand: Append.                                                        | `[(, (`                   | `A`                   |                                                                                                        |
| `+`           | Operator: Top of stack is `(`. Push `+`.                                | `[(, (, +]`               | `A`                   |                                                                                                        |
| `B`           | Operand: Append.                                                        | `[(, (, +]`               | `A B`                 |                                                                                                        |
| `)`           | Close Paren (matches `op2`): Pop until `(`. Pop `+`, append.             | `[(, (`                   | `A B +`               |                                                                                                        |
|               | Pop inner `(`, discard.                                                 | `[(`                       | `A B +`               | `(A+B)` becomes `A B +`                                                                                |
| `*`           | Operator: Top of stack is `(`. Push `*`.                                | `[(, *]`                   | `A B +`               |                                                                                                        |
| `C`           | Operand: Append.                                                        | `[(, *]`                   | `A B + C`             |                                                                                                        |
| `)`           | Close Paren (matches `op1`): Pop until `(`. Pop `*`, append.             | `[(`                       | `A B + C *`           |                                                                                                        |
|               | Pop outer `(`, discard.                                                 | `[]`                       | `A B + C *`           | Base for `^`, `((A+B)*C)`, becomes `A B + C *`                                                         |
| `^`           | Operator: Stack empty. Push `^`.                                        | `[^]`                      | `A B + C *`           |                                                                                                        |
| `D`           | Operand: Append.                                                        | `[^]`                      | `A B + C * D`         |                                                                                                        |
| `-`           | Operator: `^` (top, prec 3) > `-` (curr, prec 1). Pop `^`, append.      | `[]`                       | `A B + C * D ^`       |                                                                                                        |
|               | Stack empty. Push `-`.                                                  | `[-]`                      | `A B + C * D ^`       |                                                                                                        |
| `E`           | Operand: Append.                                                        | `[-]`                      | `A B + C * D ^ E`     |                                                                                                        |
| End of Expr   | Pop remaining. Pop `-`, append.                                         | `[]`                       | `A B + C * D ^ E -` |                                                                                                        |

**Final Postfix Expression: `A B + C * D ^ E -`**

---

While learning data structures and algorithms (the picture shows the Shunting-Yard algorithm that converts a infix expression to a postfix expression), I became a ‘human compiler’ like the example above, and used pen and paper to implement the algorithm and to track the intermediate state in the algorithm. Do you think this exercise is useful for learning data structures and algorithms?