Basic TreeNode Structure Using Generics
This is the basic block for creating the binary tree. We generally call this block or the structure as a Node. So this is how a single node is created. This in itself is a tree and when we pile the number of nodes, it become a big tree.
Here is the code, to create the TreeNode.
/**
* Basic Structure of the Tree. Or the Single unit of a tree.
* @author Sonu Mishra
* @paramType of the Node for the tree. Like. String, Integer
*/
TreeNode< E extends Comparable<? super E>>
{
public TreeNode< E > left;
public TreeNode< E > right;
E value;
public TreeNode(TreeNode< E > left, TreeNode< E > right, E value) {
this.left = left;
this.right = right;
this.value = value;
}
/**
* If a node doesn't have left and right child, it is leaf node.
* @param node check whether this node is leaf node or not.
* @return either true or false
*/
This is the basic block for creating the binary tree. We generally call this block or the structure as a Node. So this is how a single node is created. This in itself is a tree and when we pile the number of nodes, it become a big tree.
Here is the code, to create the TreeNode.
/**
* Basic Structure of the Tree. Or the Single unit of a tree.
* @author Sonu Mishra
* @param
*/
TreeNode< E extends Comparable<? super E>>
{
public TreeNode< E > left;
public TreeNode< E > right;
E value;
public TreeNode(TreeNode< E > left, TreeNode< E > right, E value) {
this.left = left;
this.right = right;
this.value = value;
}
/**
* If a node doesn't have left and right child, it is leaf node.
* @param node check whether this node is leaf node or not.
* @return either true or false
*/