
The postfix code can be used, if needed, to reconstruct a tree. Thus, the postfix code can be used as a compact way to store a tree.
( X & Y ) | ( ( ! X ) & ( ! Y ) )
3. Postfix representation and code list.
Here is the postfix representation.
x y & x ! y ! & |
Here is a list that can represent the code.
codeList1 = [
["var", "x"],
["var", "y"],
["op2", "and"],
["var", "x"],
["op1", "not"],
["var", "y"],
["op1", "not"],
["op2", "and"],
["op2", "or"],
]
Here is a code example, with print statements interspersed to trace what is happening.
Here is the JavaScript code.
Here is the output of the JavaScript code.
Note that the printed output of a list (above) is not pretty-printed, but printed using the default print behavior. For pretty-print purposes, a special-purpose routine is needed to output the structure in the form desired (omitted, left as an exercise).