The Department of Computer Science & Engineering |
STUART C. SHAPIRO: CSE
116 B
|
If the root is at level 0: each level, d contains 2d nodes; a tree of height h contains 2h+1-1 nodes. In binary:
|
Pseudocode evaluator of postfix expressions:
int postfixEvaluator(TokenStream stream) { Stack stack; Token token; while (stream.hasNext()) { token = stream.next(); if (token instanceof int) stack.push(token); else { // token is an operator opnd2 = stack.pop(); opnd1 = stack.pop(); stack.push(apply(token, opnd1, opnd2)); } } return stack.top(); }