# Include "stdafx. h "# include <iostream> using namespace std; struct BinaryTreeNode {int m_nValue; BinaryTreeNode * m_pLeft; values * m_pRight;}; bool values (BinaryTreeNode * pRoot1, BinaryTreeNode * pRoot2) {if (pRoot2 = NULL) {return true;} if (pRoot1 = NULL) {return false;} if (pRoot1-> m_nValue! = PRoot2-> m_nValue) {return false;} return DoesTree1haveTree2 (pRoot1-> m_pLeft, pRoot2-> m_pLeft) & Signature (pRoot1-> m_pRight, pRoot2-> m_pRight );} // determine whether B is A sub-structure bool IsSubStruct (BinaryTreeNode * pRootOfTreeA, BinaryTreeNode * pRootOfTreeB) {bool result = false; if (pRootOfTreeA! = NULL & pRootOfTreeB! = NULL) {if (pRootOfTreeA-> m_nValue = pRootOfTreeB-> m_nValue) {result = DoesTree1haveTree2 (pRootOfTreeA, pRootOfTreeB);} if (! Result) {result = IsSubStruct (pRootOfTreeA-> m_pLeft, pRootOfTreeB);} if (! Result) {result = IsSubStruct (pRootOfTreeA-> m_pRight, pRootOfTreeB) ;}} return result ;}// create a binary tree in the first order, input-1 indicates that the node is empty void CreateBinaryTree (BinaryTreeNode * & pRoot) {int nNodeValue = 0; cin> nNodeValue; if (-1 = nNodeValue) {return ;} else {pRoot = new BinaryTreeNode (); pRoot-> m_nValue = nNodeValue; CreateBinaryTree (pRoot-> m_pLeft); CreateBinaryTree (pRoot-> m_pRight);} void PrintInOrder (Binary TreeNode * & pRoot) {if (pRoot! = NULL) {PrintInOrder (pRoot-> m_pLeft); cout <pRoot-> m_nValue <""; PrintInOrder (pRoot-> m_pRight );}} int _ tmain (int argc, _ TCHAR * argv []) {BinaryTreeNode * pRoot1 = NULL; CreateBinaryTree (pRoot1); PrintInOrder (pRoot1); cout <endl; binaryTreeNode * pRoot2 = NULL; CreateBinaryTree (pRoot2); PrintInOrder (pRoot2); cout <endl; cout <"Root2 is a subset of Root1, returns 1; otherwise, returns 0. result: "<IsSubStruct (pRoot1, p Root2) <endl; system ("pause"); return 0 ;}# include "stdafx. h "# include <iostream> using namespace std; struct BinaryTreeNode {int m_nValue; BinaryTreeNode * m_pLeft; values * m_pRight;}; bool values (BinaryTreeNode * pRoot1, BinaryTreeNode * pRoot2) {if (pRoot2 = NULL) {return true;} if (pRoot1 = NULL) {return false;} if (pRoot1-> m_nValue! = PRoot2-> m_nValue) {return false;} return DoesTree1haveTree2 (pRoot1-> m_pLeft, pRoot2-> m_pLeft) & Signature (pRoot1-> m_pRight, pRoot2-> m_pRight );} // determine whether B is A sub-structure bool IsSubStruct (BinaryTreeNode * pRootOfTreeA, BinaryTreeNode * pRootOfTreeB) {bool result = false; if (pRootOfTreeA! = NULL & pRootOfTreeB! = NULL) {if (pRootOfTreeA-> m_nValue = pRootOfTreeB-> m_nValue) {result = DoesTree1haveTree2 (pRootOfTreeA, pRootOfTreeB);} if (! Result) {result = IsSubStruct (pRootOfTreeA-> m_pLeft, pRootOfTreeB);} if (! Result) {result = IsSubStruct (pRootOfTreeA-> m_pRight, pRootOfTreeB) ;}} return result ;}// create a binary tree in the first order, input-1 indicates that the node is empty void CreateBinaryTree (BinaryTreeNode * & pRoot) {int nNodeValue = 0; cin> nNodeValue; if (-1 = nNodeValue) {return ;} else {pRoot = new BinaryTreeNode (); pRoot-> m_nValue = nNodeValue; CreateBinaryTree (pRoot-> m_pLeft); CreateBinaryTree (pRoot-> m_pRight );}} void PrintInOrder (BinaryTreeNode * & pRoot) {If (pRoot! = NULL) {PrintInOrder (pRoot-> m_pLeft); cout <pRoot-> m_nValue <""; PrintInOrder (pRoot-> m_pRight );}} int _ tmain (int argc, _ TCHAR * argv []) {BinaryTreeNode * pRoot1 = NULL; CreateBinaryTree (pRoot1); PrintInOrder (pRoot1); cout <endl; binaryTreeNode * pRoot2 = NULL; CreateBinaryTree (pRoot2); PrintInOrder (pRoot2); cout <endl; cout <"Root2 is a subset of Root1, returns 1; otherwise, returns 0. result: "<IsSubStruct (pRoot1, pRoot2) <endl; system (" pause "); return 0 ;}