Java program to implement Binary Tree using the Linked List
In this program, we need to create the binary tree by inserting nodes and displaying nodes in in-order fashion. A typical binary tree can be represented as follows:
In the binary tree, each node can have at most two children. Each node can have zero, one or two children. Each node in the binary tree contains the following information:
Data that represents value stored in the node.
Left that represents the pointer to the left child.
Right that represents the pointer to the right child.
Define Node class which has three attributes namely: data left and right. Here, left represents the left child of the node and right represents the right child of the node.
a. insert() will add a new node to the tree:
a. Inorder() will display nodes of the tree in inorder fashion.
Binary tree after insertion 1 Binary tree after insertion 2 1 3 Binary tree after insertion 4 2 5 1 3 Binary tree after insertion 4 2 5 1 6 3 7