2016-11-05 97 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實施的那些。