Question: Consider the following generic tree class in Java..... (a) Write an assignment statement such that variable root refers to a Tree of Intergers with at

Consider the following generic tree class in Java.....Consider the following generic tree class in Java..... (a) Write an assignment

(a) Write an assignment statement such that variable root refers to a Tree of Intergers with at last four nodes.

(b) Write a functional interface named Power that abstracts away the fold algorithm's mixing operation over trees. Its imposes a mix method on its implementers. The method accepts three parameters in the following order: a generic T for the current node's value, a generic U for the left child's folded value, and a generic U for the right child's folded value. It returns a U.

(c) Write method Tree.fold that accepts a Mixer and a generic U representing the zero value. It mixes together the tree node's value and the values from folding the left and right children. If a child noe doesn't exist (is null) , the zero value is mixed in instead

(d) Calculate the following values using only call to Tree.fold and a lambda.

(i) Assign to variable sum the sum of the nodes in the tree starting at root.

(ii) Assign to variable count the number of nodes in the tree starting at root.

(iii) Assign to variable inorder a String of bracketed node values sorted in an in-order way. Example: If the root has 5, left child 12, and right child 2, then inorder has value "[17][5][2]".

2. Arborithms Consider the following generic tree class in Java public class Tree f private T value; private Tree leftChild; private Tree rightChild; public Tree(T value, Tree leftChild, Tree rightChild) f this.value = value; this. leftChild = leftChild; this, rightChild = rightChild; (a) Write an assignment statement such that variable root refers to a Tree of Integers with at least four nodes. 2. Arborithms Consider the following generic tree class in Java public class Tree f private T value; private Tree leftChild; private Tree rightChild; public Tree(T value, Tree leftChild, Tree rightChild) f this.value = value; this. leftChild = leftChild; this, rightChild = rightChild; (a) Write an assignment statement such that variable root refers to a Tree of Integers with at least four nodes

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!