Java 多叉树 遍历
发布网友
发布时间:2022-04-26 01:51
我来回答
共1个回答
热心网友
时间:2022-06-19 17:30
public class test {
private List<String[]> lists = new ArrayList<String[]>();
public test(){
lists.add(new String[]{"0","1"});
lists.add(new String[]{"0","2"});
lists.add(new String[]{"0","3"});
lists.add(new String[]{"3","4"});
lists.add(new String[]{"3","5"});
lists.add(new String[]{"3","6"});
lists.add(new String[]{"6","7"});
lists.add(new String[]{"6","8"});
}
public boolean testA(String s,String sysos){
boolean f = true;
for (int j = 0; j < lists.size(); j++) {
String[] str = lists.get(j);
if(str[0].equals(s)){
if(testA(str[1],sysos+s)){
f = false;
}
}
}
if(f){
System.out.println(sysos+s);
}
return f;
}
public static void main(String[] args){
test t = new test();
t.testA("0","");
}
}追问思路是对的,可以交流交流吗?q:460757952