New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating resource.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
struct treenode{
  int value;
  struct treenode* left;
  struct treenode* right;
}
type treenode =
    Node of {
        value: int;
        left: treenode;
        right: treenode
    }
    | Leaf
type treenode
  integer :: value
  type (treenode), pointer :: left
  type (treenode), pointer :: right
end type treenode
struct binary_tree
{
 int data;
 binary_tree *left = nullptr, *right = nullptr;
};
class BinaryTree<T>:IComparable<T>
{
 T value;
 BinaryTree<T> leftChild;
 BinaryTree<T> rightChild;
}
struct BinaryTree(T)
{
	T data;
	BinaryTree* left;
	BinaryTree* right;
}
class Node<T> {
  final T value;
  Node<T> left, right;
  Node(this.value, {this.left, this.right});
]
defmodule BinaryTree do
	defstruct data: nil, left: nil, right: nil
end
-type binary_tree(T) ::
	#{ data := T
	 , left := binary_tree(T)
	 , right := binary_tree(T)
	 }.
type binary_tree
    integer :: value
    type(binary_tree), allocatable :: left
    type(binary_tree), allocatable :: right
end type binary_tree
type BinTree struct {
	Key keyType
	Deco valueType
	Left *BinTree
	Right *BinTree
}
data BT x = BEnd | BNode (BT x) x (BT x)
class Node {
  constructor (data) {
    this.data = data
    this.left = null
    this.right = null
  }
}
class Node {
  constructor (data) {
    this.data = data
    this.left = null
    this.right = null
  }
}
class BinTree<T extends Comparable<T>>{
   T value;
   BinTree<T> left;
   BinTree<T> right;
}
(defclass node ()
  ((value 
      :initarg :value :initform nil 
      :accessor node-value)
   (left-child 
      :initarg :left-child :initform nil 
      :accessor node-left-child)
   (right-child 
      :initarg :right-child :initform nil 
      :accessor node-right-child)))
local function BinTree(v, l, r)
	return {
		val = v,
		left = l,
		right = r
	}
end
class BNode
{
    public $data;
    public $lNode;
    public $rNode;

    public function __construct($item)
    {
        $this->data = $item;
        $this->lNode = null;
        $this->rNode = null;
    }
}
type
  generic BinTree<T> = class
    Value: T;
    Left, Right: BinTree;
  end;   
use Moops;
class Tree::Binary {
    has 'left', is => 'ro', isa => Maybe[InstanceOf['Tree::Binary']];
    has 'right', is => 'ro', isa => Maybe[InstanceOf['Tree::Binary']];
    has 'val', is => 'ro', isa => Int;
}
my $t = Tree::Binary->new(
    val => 42,
    left => Tree::Binary->new(val => 23),
    right => Tree::Binary->new(
        val => 1729,
        right => Tree::Binary->new(val => -1)
    )
);
__END__
      42
    ↙    ↘
  23     1729
 ↙  ↘   ↙    ↘
∅    ∅ ∅     -1
class Node:
	def __init__(self, data):
		self.data = data
		self.left = None
		self.right = None
class Node:
  def __init__(self, data, left_child, right_child):
    self.data = data
    self._left_child = left_child
    self._right_child = right_child
Node = Struct.new(:left, :right, :value)
parent = Node.new(Node.new, Node.new)
struct BinTree<T> {
    value: T,
    left: Option<Box<BinTree<T>>>,
    right: Option<Box<BinTree<T>>>,
}
(define (make-btree value left right)
  (cons value (cons left right)))

(define (btree-value bt) (car bt))
(define (btree-left bt) (cadr bt))
(define (btree-right bt) (cddr bt))