我需要在這兩個類實現一個尺寸()和真的不知道如何開始:鏈表的大小()
interface Tree extends Cloneable {
int size();
}
class Fruit implements Tree {
@Override public int size() {
}
}
class Branch implements Tree {
private List<Tree> children = new LinkedList<Tree>();
public List<Tree> getChildren() {
return Collections.unmodifiableList(children);
}
public void addChild(Tree tree) {
children.add(tree);
}
@Override public int size() {
}
}
任何人都可以指導我在正確的方向上如何創建這兩個尺寸() 方法?我需要他們來計算樹中實際水果的數量。
這不是一個鏈表。那是一棵樹。 – 2011-04-14 17:26:42
public class Fruit implements Tree { \t @Override public int size(){ \t \t return this.size(); \t \t \t}} 公共類分公司實現樹{ \t私人列表孩子=新的LinkedList (); \t public List getChildren(){return Collections.unmodifiableList(children); } \t public void addChild(Tree tree){children.add(tree); } \t @Override public int size(){ \t \t return this.getChildren()。size(); \t} } –
Alpdog14
2011-04-14 17:42:23