注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
本帖最后由 wang4498 于 2022-2-25 18:27 编辑
大致意思是这样的,没答好
Considering a N-ary tree with this node structure:
class NodeTypeA {
String payload;
List<NodeTypeA> children;
}
And we want to convert the tree to NodeTypeB tree, but the internal structure of NodeTypeB is invisible, and we can only construct the new tree using two method:
//This method can only convert leaf NodeTypeA (no children)
public NodeTypeB convertLeaf(NodeTypeA nodeTypeA);
//This method can convert a non-leaf NodeTypeA as long as its children are converted
public NodeTypeB convertParent(NodeTypeA parentNodeTypeA, List<NodeTypeB> nodeTypeBs);
The recursive solution is trivial, how can we do it in non-recursive way?
|