Back to problems
COMP2521
21T3 Q8 — Sum of odd values (rebuild tree)
stdin: N, then the preorder (N ints), then the inorder (N ints) of a binary tree with distinct values. Rebuild the tree and print the sum of all odd node values.
Single-file C (gcc -O0 -Wall). Self-contained reframing of the exam's ADT-completion question. From COMP2521 21T3 Sample.
Samples
stdin
5 1 2 4 3 5 4 2 1 5 3
expected
9
c-gcc
14