二叉树的存储结构为: structBTreeNode{ElemTypedata;BTreeNode* lchild;BTreeNode* rchild;};请写出其非递归的中序遍历算法voidInOrderWithoutRecursion(BTreeNode* root) {if (root == NULL) return;BTNode* p = root;stack<BTNode*> s;while (!s.empty() || p) {//入栈中,左子树的左子树在入栈while (p) {_________________;__________________;}if (!s.empty()){//当p为空时,说明根和左子树都遍历完,该进入右子树 ________________;cout<< ”“<< p->data; _________________;}}cout<<endl;}
二叉树的存储结构为: structBTreeNode{ElemTypedata;BTreeNode* lchild;BTreeNode* rchild;};请写出其非递归的中序遍历算法voidInOrderWithoutRecursion(BTreeNode* root) {if (root == NULL) return;BTNode* p = root;stack<BTNode*> s;while (!s.empty() || p) {//入栈中,左子树的左子树在入栈while (p) {_________________;__________________;}if (!s.empty()){//当p为空时,说明根和左子树都遍历完,该进入右子树 ________________;cout<< ”“<< p->data; _________________;}}cout<<endl;}
1