Implementation
C

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
class BinTree<T extends Comparable<T>>{
   T value;
   BinTree<T> left;
   BinTree<T> right;
}
type BinTree struct {
	Key keyType
	Deco valueType
	Left *BinTree
	Right *BinTree
}
struct BinaryTree(T)
{
	T data;
	BinaryTree* left;
	BinaryTree* right;
}
struct BinTree<T> {
    value: T,
    left: Option<Box<BinTree<T>>>,
    right: Option<Box<BinTree<T>>>,
}
class Node<T> {
  final T value;
  Node<T> left, right;
  Node(this.value, {this.left, this.right});
]
type
  generic BinTree<T> = class
    Value: T;
    Left, Right: BinTree;
  end;   
Node = Struct.new(:left, :right, :value)
parent = Node.new(Node.new, Node.new)
data BT x = BEnd | BNode (BT x) x (BT x)
defmodule BinaryTree do
	defstruct data: nil, left: nil, right: nil
end
class Node:
	def __init__(self, data):
		self.data = data
		self.left = None
		self.right = None
class BinaryTree<T>:IComparable<T>
{
 T value;
 BinaryTree<T> leftChild;
 BinaryTree<T> rightChild;
}
class BNode
{
    public $data;
    public $lNode;
    public $rNode;

    public function __construct($item)
    {
        $this->data = $item;
        $this->lNode = null;
        $this->rNode = null;
    }
}
-type binary_tree(T) ::
	#{ data := T
	 , left := binary_tree(T)
	 , right := binary_tree(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))
local function BinTree(v, l, r)
	return {
		val = v,
		left = l,
		right = r
	}
end
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
  }
}
(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)))
type treenode
  integer :: value
  type (treenode), pointer :: left
  type (treenode), pointer :: right
end type treenode
type treenode =
    Node of {
        value: int;
        left: treenode;
        right: treenode
    }
    | Leaf
class Node:
  def __init__(self, data, left_child, right_child):
    self.data = data
    self._left_child = left_child
    self._right_child = right_child
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
struct binary_tree
{
 int data;
 binary_tree *left = nullptr, *right = nullptr;
};
type binary_tree
    integer :: value
    type(binary_tree), allocatable :: left
    type(binary_tree), allocatable :: right
end type binary_tree