我使用以下方法遍历*300 000级别的二叉树:
Node* find(int v){
if(value==v)
return this;
else if(right && value<v)
return right->find(v);
else if(left && value>v)
return left->find(v);
}
Run Code Online (Sandbox Code Playgroud)
但是由于堆栈溢出,我得到了分段错误.关于如何在没有递归函数调用开销的情况下遍历深层树的任何想法?
*"遍历"我的意思是"搜索具有给定值的节点",而不是完整的树遍历.
c++ algorithm binary-tree binary-search-tree data-structures