二叉樹的類型 數據結構與算法,二叉樹交換左右子樹算法?
數據結構與算法,二叉樹交換左右子樹算法?傳入樹的根節(jié)點:exchangelr(&root)//根是樹的根節(jié)點。Void exchangelr(treenode*root){treenode*TM
數據結構與算法,二叉樹交換左右子樹算法?
傳入樹的根節(jié)點:exchangelr(&root)//根是樹的根節(jié)點。Void exchangelr(treenode*root){treenode*TMP if(root==null)return//左子樹交換exchangelr(root->left)//右子樹交換exchangelr(root->right)//當前節(jié)點的左右子樹TMP=root->left root->left=root->right root->right=TMP}
數據結構中,怎樣以二叉鏈表為存儲結構,分別寫出求二叉樹結點總數及葉子總數的算法?
intcountnode(btnode*t)//節(jié)點總數{int numif(t==null)num=0elsenum=1 countnode(t->lch)countnode(t->rch)return(num)}void countleaf(btnode*t)//葉節(jié)點總數{if(t!=null){if(T->lch==null&;T->rch==null)count//全局變量countleaf(T->lch)countleaf(T->rch)}