【发布时间】:2013-11-20 22:04:24
【问题描述】:
当我在写一个 BST 查找函数时:
public static boolean find(Node root, int value){
if(root == null){
return false;
}
Node iter = root;
while(iter != null){
.....
}
return false;
}
编译器会删除
if(root == null){
return false;
}
或者不。因为我无论如何都在 while 循环中检查条件。
谢谢。
ps。我刚刚意识到,我是按值传递的,所以不需要 iter Node.. 太多 C
【问题讨论】:
-
这里明显的问题是:为什么要检查两次?
-
我不应该检查两次(一次就足够了),只是想知道?
标签: java data-structures binary-search-tree compiler-optimization