二叉树中序遍历(非递归)
void Show_InOder_BST(BSTNode* root)
{
assert(root != NULL);
std::stack<BSTNode*> st;
st.push(root);
bool tag=true;
while (!st.empty())
{
while (tag && st.top()->leftchild != NULL)
{
st.push(st.top()->leftchild);
}
BSTNode* tmp;
tmp = st.top();
st.pop();
printf("%d ", tmp->data);
if (tmp->rightchild != NULL)
{
st.push(tmp->rightchild);
tag = true;
}
else
{
tag = false;
}
}
}

浙公网安备 33010602011771号