如何从对象中获取特定值? 我试图获得例如 的值。如何基于成员变量的值将对象添加到二叉树?
ListOfPpl newListOfPpl = new ListOfPpl(id, name, age);
Object item = newListOfPpl;
如何从对象项获取名称值? 即使它很容易或不感兴趣,你可以帮助我吗?
编辑:我正在尝试构建一个包含ListOfPpl节点的二叉树,并且需要在词典中对它进行排序。这是我在代码中插入节点的代码。任何线索?
public void insert(Object item){
Node current = root;
Node follow = null;
if(!isEmpty()){
root = new Node(item, null, null);
return;
}boolean left = false, right = false;
while(current != null){
follow = current;
left = false;
right = false;
//I need to compare and sort it
if(item.compareTo(current.getFighter()) < 0){
current = current.getLeft();
left = true;
}else {
current = current.getRight();
right = true;
}
}if(left)
follow.setLeft(new Node(item, null, null));
else
follow.setRight(new Node(item, null, null));
}
恐怕,通常问题中包含“任何人帮助我!”有被忽视的高风险。更好地使用'两块钱快速回答!'。 – 2010-06-06 13:36:28
好建议哈哈哈谢谢 – Max 2010-06-06 13:56:46