一个二叉树非递归遍历小问题
void inordertraversenocur(BST T)
{
stack<struct BSTnode *> S;
BST p = T;
BST q = (BST)malloc(sizeof(node));
while (p || !S.empty());
{
if (p)
{
S.push(p);
p = p->lchild;
}
else
{
q = S.top();
S.pop();
printf("%d ",p->num);
p = q->rchild;
}
}
}
我这里初始化stack是错误了吗,为什么我调试不了,一到stack那行就弹connot open file(这个好像是dgb的问题),但我跳过这行再到while行,调试的光标就不见了{
stack<struct BSTnode *> S;
BST p = T;
BST q = (BST)malloc(sizeof(node));
while (p || !S.empty());
{
if (p)
{
S.push(p);
p = p->lchild;
}
else
{
q = S.top();
S.pop();
printf("%d ",p->num);
p = q->rchild;
}
}
}