1
私は抽象クラスの要素のリストを持っていると私はそれをソートしてみたとき、私はカスタムクラスは:配列内の2つの要素を比較するのに失敗しました
「アレイ内の2つの要素を比較するために失敗しました」というメッセージと例外を取得抽象クラス:
派生クラス:
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;
}
}
誰も私が間違ってここにやっているものを私に教えてくださいことはできますか?私はノードのリストを作成し、メソッドの並べ替えを呼び出したい、ありがとう。