是否可以将未知数据类型与int
. 我正在尝试编写一个获取最大节点数的函数,但数据类型是 E 而不是int
.
到目前为止我的代码是..
public E getMax() {
if (isEmpty()) {
throw new NoSuchElementException(" error " ) ;
} else {
Node n = first;
E x ;
int max = 0 ;
while (n!=null) {
if (n.data > x) {
max = n.data;
}
}
return x;
}
}