未捕获的无效参数:'Node' 的实例
Uncaught Invalid argument: Instance of 'Node'
在使用排序函数时,我创建的已实现节点似乎会导致一些问题。
我在MergeSort的Merge函数中追踪到了节点的比较。也就是说,有问题的代码行是:
if (_tmpArray[i] <= _tmpArray[j])
_tmpArray 在构造函数中定义,但在合并中给定内容值
operator ==
、operator <
、operator <=
的节点实现如下
bool operator ==( Node<T> other) => identical(this, other);
bool operator <( Node<T> other){
//other is of same type, T.
if (_value.compareTo(other) == -1){
return true;
}
return false;
}
bool operator <= ( Node<T> other){
return (this == other) || (this < other);
}
看来我的实现可能是错误的。我正在使用大小为 400、T = int.
的列表在 main 中进行测试
附件是我的 Dartpad 文件:https://dartpad.dartlang.org/612422345f1ac8a27f8e
似乎 _value.compareTo
的比较不正确,因为 T
在 int
为 T
的情况下没有 compareTo。将 int 转换为 "String" 时,虽然 compareTo
具有可比性,但它仍然显示相同的错误。
//other is of same type, T.
if (_value.compareTo(other._value) == -1){
// ^^^^^^^ was missing
return true;
}
return false;
在使用排序函数时,我创建的已实现节点似乎会导致一些问题。
我在MergeSort的Merge函数中追踪到了节点的比较。也就是说,有问题的代码行是:
if (_tmpArray[i] <= _tmpArray[j])
_tmpArray 在构造函数中定义,但在合并中给定内容值
operator ==
、operator <
、operator <=
的节点实现如下
bool operator ==( Node<T> other) => identical(this, other);
bool operator <( Node<T> other){
//other is of same type, T.
if (_value.compareTo(other) == -1){
return true;
}
return false;
}
bool operator <= ( Node<T> other){
return (this == other) || (this < other);
}
看来我的实现可能是错误的。我正在使用大小为 400、T = int.
的列表在 main 中进行测试附件是我的 Dartpad 文件:https://dartpad.dartlang.org/612422345f1ac8a27f8e
似乎 _value.compareTo
的比较不正确,因为 T
在 int
为 T
的情况下没有 compareTo。将 int 转换为 "String" 时,虽然 compareTo
具有可比性,但它仍然显示相同的错误。
//other is of same type, T.
if (_value.compareTo(other._value) == -1){
// ^^^^^^^ was missing
return true;
}
return false;