Generic Interface for Binary Tree

jengfad profile image Jennifer Fadriquela Updated on ・1 min read

A node in a binary tree can only have left and right child nodes. This structure can go deeper. As an effort to strongly-type this kind of data, I came up with below implementation of generic interface and class.

public interface INode<T>
    T LeftNode { get; set; }
    T RightNode { get; set; }
    string Path { get; set; }

public class Node: INode<Node>
    public Node LeftNode { get; set; }
    public Node RightNode { get; set; }
    public string Path { get; set; }

Node class seems a little quirky because it passes its own type to INode.


Editor guide