Data Structures and Algorithms
with Object-Oriented Design Patterns in JavaIn prefix notation the operator is written before its operands. Therefore, in order to print the prefix expression from an expression tree, preorder traversal is done. That is, at every non-terminal node we do the following:
we get the prefix expression
While this notation may appear unfamiliar at first, consider the result obtained when we spell out the names of the operators:
plus (div (a,b), times (minus (c,d), e))This is precisely the notation used in a typical programming language to invoke user defined methods plus, minus, times, and div.
Copyright © 1998 by Bruno R. Preiss, P.Eng. All rights reserved.