# 关于菜单树排序问题的解决方案（二）

### 使用多叉树对菜单树进行遍历

1. 多叉树
``````public class MultiTree<N extends TreeNode>{
private N node;
private List<MultiTree> children;
/**
* 返回排好序的List
*/
public List<N> getSortTreeList(List<N> nodeList){
return traverseTree(createTree(nodeList));
}
/**
* 根据菜单树List创建多叉树
*/
public List<MultiTree> createTree(List<N> nList){
List<MultiTree> operateTree=new ArrayList<>();
List<MultiTree> rootTree=new ArrayList<>();
for (N n:nList){
}
for (MultiTree tree1:operateTree){
if (tree1.node.isRootNode()){
}
for (MultiTree tree2:operateTree){
if (tree2.node.getPId()!=null&&tree2.node.getPId().equals(tree1.node.getId())){
}
}
}
return rootTree;
}
/**
* 遍历多叉树并返回排好序的List
*/
public List<N> traverseTree(List<MultiTree> trees){
List<N> resultTree=new ArrayList<>();
for (MultiTree tree:trees){
if (tree.children!=null&&tree.children.size()>0){
}
}
return resultTree;
}
public MultiTree() {
}
public MultiTree(N node) {
this.node = node;
children=new ArrayList<>();
}
}
``````
1. 多叉树方式的使用
``````public class Main {
public static void main(String []args){
List<TestNode> testNodes=new ArrayList<>();
//建立多叉树进行遍历
MultiTree<TestNode> tree=new MultiTree<>();
List<TestNode> result=tree.getSortTreeList(testNodes);
for (TestNode node:result){
System.out.println(node);
}
}
}
``````