两个字符串我需要从字符串的二叉树显示不同节点的“路径”。该函数接收两个节点(开始和结束),假设它们存在于树中。该树不是有序的,不能订购。我一直在使用预订策略。搜索未排序二叉树
例如,如果输入的是周一和月份的结果应该是:
monday party of month
使用序结果是
monday party of friday month
有谁知道打印在正确的道路?
family
/ \
day monday
/ \ / \
zoo night party brother
/\/\ /\ /\
lion of at club
/\
friday month
public void fa(NodeArbre inicial,NodeArbre fi){
if(inicial!=null){
System.out.println(inicial._contingut+ " _ ");
fa(inicial._esq,fi);
fa(inicial._dret,fi);
}
}
你能只向下遍历树,或者你可以通过父母以及(如从周一到狮子)? – callyalater
好的。然后,我会觉得这个问题是有向图,并使用[Dijkstra算法(https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm)或[克鲁斯卡的(https://en.wikipedia.org/wiki/Kruskal%27s_algorithm)来遍历它。 – callyalater