We are asked to write the following recursive methods in given...

Question

# We are asked to write the following recursive methods in given...

We are asked to write the following recursive methods in given class bellow :

1. boolean isFull (): that returns the true if the binary tree is full, false otherwise.
A full binary tree is defined as a binary tree in which all nodes have either zero or two
child nodes.

2. int getItemLevel (E data): returns the level of the item data, and 0 if the item does not
exist in the tree.
3. void printItemsAtLevel (int level): prints the nodes at the level given as a parameter.

Given the class BinaryTree:

public class BinaryTree <E> {
protected static class Node<E> {

public E data;

public Node<E> left;

public Node<E> right;

public Node(E data) {
this.data = data;
left = null;
right = null;
}

@Override
public String toString() {
return data.toString();
}
}

protected BinaryTree(Node<E> root) {
this.root = root;
}

public BinaryTree(E data, BinaryTree<E> leftTree, BinaryTree<E> rightTree) {
root = new Node<>(data);
if (leftTree != null) {
root.left = leftTree.root;
} else {
root.left = null;
}
if (rightTree != null) {
root.right = rightTree.root;
} else {
root.right = null;
}
}

public BinaryTree<E> getLeftSubtree() {
if (root != null && root.left != null) {
return new BinaryTree<>(root.left);
} else {
return null;
}
}

public BinaryTree<E> getRightSubtree() {
if (root != null && root.right != null) {
return new BinaryTree<>(root.right);
} else {
return null;
}
}

public E getData() {
if (root != null) {
return root.data;
} else {
return null;
}
}

public boolean isLeaf() {

return (root == null || (root.left == null && root.right == null));
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
toString(root, 1, sb);
return sb.toString();
}

private void toString(Node<E> root, int level, StringBuilder sb) {
for (int i = 1; i < level; i++)
sb.append(" ");
if (root == null)
sb.append("null\n");
else {
sb.append(root.data+"\n");
toString(root.left, level + 1, sb);
toString(root.right, level + 1, sb);
}

}

public static BinaryTree<String> readBinaryTree(Scanner scan) {
String data = scan.nextLine().trim();
if (data.equals("null")) {
return new BinaryTree<>();
} else {
return new BinaryTree<>(data, leftTree, rightTree);
}
}

}

Solved by verified expert

sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie

sec

10,000 step-by-step explanations

## Step-by-step explanation

sectetur adipiscing elit. Nam lacinia pulvi

sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue

sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliq

sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ul

sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet

3 attachments
PNG
PNG
PNG