Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int recursiveSum(Tree<Integer> t) {
- if (t == null)
- return 0;
- int sum = t.elem();
- Set<Tree<Integer>> subtrees = t.subtrees();
- for (Tree<Integer> subtree : subtrees) {
- sum += recursiveSum(subtree);
- }
- return sum;
- }
Add Comment
Please, Sign In to add comment