C#C
C#2y ago
potzko

help with generic interface

im writing a small binary tree library for fun and ran into a small problem
I made a small interface for Node and Tree:
however the Node interface can only reference itself if that makes sense?
public interface Node<T> where T : IComparable<T>
public interface Node<T> where T : IComparable<T>
{
    T GetValue();
    Node<T>? Getleft();
    Node<T>? GetRight();
}

public class SplayTreeNode<T> : Node<T> where T : IComparable<T>
{
    private T data;
    private SplayTreeNode<T>? left;
    private SplayTreeNode<T>? right;
    private SplayTreeNode<T>? parent;

    public SplayTreeNode(T value)
    {
        data = value;
    }

    public T GetValue()
    {
        return data;
    }

    public SplayTreeNode<T>? Getleft()
    {
        return left;
    }

    public SplayTreeNode<T>? GetRight()
    {
        return right;
    }
}
Was this page helpful?