Also, a way of doing
math. Normal people do math in
infix notation, which results in problems with operator
precedence and introduces the need for
parentheses. Infix looks like this:
(2 + 3) * 5
Prefix would look like this:
* + 2 3 5
If we put the infix expression into a binary tree, we can get the prefix equivalent by traversing the tree like so:
- Write down the number or symbol at the current node.
- Go to the left node and recurse.
- Go to the right node and recurse.
I'm not up on prefix notation, so I can't really say what the benefits of it are. I know that LISP uses it to some degree. But I don't have much LISP experience either, so I might be talking out my ass. Maybe someone who knows this better can elaborate? Compare to my postfix node, which has a lot more information about all this. In general, prefix is the same idea as postfix only in reverse.