January 26, 2019

Class to represent a binary tree node in java.

A node in a binary tree contains data and reference to it’s left and right child.

You can add as many instance variables you want, because all of them represent data.

You can have multiple maps, multiple lists another class objects. Because, all of those are data.

But, objects to access the left and right child needs to be there.

I am using a simple char variable to hold name of the node. You can put anything you want in this class.

And, I have left  and right variable to refer to left and right child.

Code is very small, as it does not do anything. It’s just an encapsulation for binary tree node data.

Complete Code :-

public class BinaryTreeNode {
    char name;
    BinaryTreeNode left;
    BinaryTreeNode right;

    BinaryTreeNode() {}
    BinaryTreeNode(char name) {
    this.name = name;


Tagged on: