voidABC(BTNode*BT){ifBT{ABC(BT->left);ABC(BT->right);cout<data<
voidABC(BTNode*BT){ifBT{ABC(BT->left);ABC(BT->right);cout<data<
void ABC(BTNode * BT){if BT {ABC (BT->;left);ABC (BT->;right);cout<;<;BT->;data<;<;' ';}}该算法的功能是
void ABC(BTNode * BT){if BT {ABC (BT->;left);ABC (BT->;right);cout<;<;BT->;data<;<;' ';}}该算法的功能是
二叉树的存储结构为: 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