我想递归地构建一个数组我以这种方式开始并且无法弄清楚如何正确地做到这一点:
public class ConnectivityNode {
private Server server;
private ConnectivityNode parent;
private ArrayList<ConnectivityNode> children;
...
public Server[] getServerRoute(){
if(this.parent == null) { return null; }
return this.server + this.parent.getServerRoute(); //of course this isnt correct
}
}
这个想法是得到一个Server
s的数组
{ parent.parent.server1, parent.server2, server3 }