Question
Java Programming Complete the height() method Complete the isCompleteBinaryTree() method Code: import java.util.LinkedList; import java.util.Queue; public class BinaryTree { public TreeNode root; public BinaryTree(){ }
Java Programming
Complete the height() method
Complete the isCompleteBinaryTree() method
Code:
import java.util.LinkedList;
import java.util.Queue;
public class BinaryTree
public TreeNode
public BinaryTree(){
}
public static class TreeNode
public E element;
public TreeNode
public TreeNode
public TreeNode(E o) {
element = o;
}
}
/******************************************************************
* Return the height of this binary tree.
* The height of the tree is the height of root node.
* Hint: Use recursive algorithm, you can use a helper method
* ****************************************************************/
public int height(){
//TODO
return 0;
}
/******************************************************************
* Return if the binary tree is complete
* Hint: scan the node from left to right by level, if there is a
* node has no left child but has right child, return false; if
* there is a node has left child, but has no right child, future
* nodes can not have any child, otherwise return false. You can
* take printTree method in TestMyTree as a reference.
* ****************************************************************/
public boolean isCompleteBinaryTree(){
//TODO
return true;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started