2016-11-05 128 views
1

我有抽象类元素的列表,当我试图解决它,我得到与“无法比较数组中的两个元素”自定义类:无法在数组中比较两个元素

消息异常抽象类:

​​

派生类:

public class Interrior : Node 
{ 
    public Interrior(byte age, Node left, Node right) 
    { 
     Age = age; 
     Left = left; 
     Right = right; 
     Weight = Left.Weight + Right.Weight; 
    } 
    public byte Age { get; } 
    public Node Left { get; } 
    public Node Right { get; } 
    public override int CompareTo(Interrior node) 
    { 
     var result = CompareWeights(node); 
     if (result == 0) result = this.Age < node.Age ? -1 : 1; 
     return result; 
    } 
    public override int CompareTo(Leaf node) 
    { 
     var result = CompareWeights(node); 
     if (result == 0) result = 1; 
     return result; 
    } 
} 
public class Leaf : Node 
{ 
    public Leaf(byte symbol) 
    { 
     Symbol = symbol; 
     Weight = 1; 
    } 
    public byte Symbol { get; } 
    public override int CompareTo(Interrior node) 
    { 
     var result = CompareWeights(node); 
     if (result == 0) result = -1; 
     return result; 
    } 

    public override int CompareTo(Leaf node) 
    { 
     var result = CompareWeights(node); 
     if (result == 0) result = this.Symbol < node.Symbol ? -1 : 1; 
     return result; 
    } 
} 

有人能告诉我什么,我做错了什么?我想创建节点列表并调用一个排序方法,谢谢。

回答

0

您没有可用的余额<Node>。实现它,并将它委托给您为Interior和Leaf实施的那些。