有趣的BackTracking算法
发布时间
阅读量:
阅读量
偶然间接触到一些需要用到「回溯算法」的实际案例,使我想起学生时代曾接触过的几种相关题型,时隔多年,特此进行一次简要的回顾。
1.二叉树遍历方法解析
public class TreeSearchDemo {
public static void main(String[] args) {
new TreeSearchDemo().testBinTree1();
}
public void testBinTree1() {
TreeNode root = makeTestTree();
List<TreeNode> result = new ArrayList<>();
preOrder(root, result);
//inOrder(root, result);
//postOrder(root, result);
for (TreeNode item : result) {
System.out.print(item.data);
}
System.out.println();
}
/** * 前序遍历
*
全部评论 (0)
还没有任何评论哟~
