【數據結構】-樹-交換每個節點的左右孩子

遞歸-後序交換每個節點的左右孩子

代碼:

void swap_child(BiTree &T) {
	if (T) {
		swap_child(T->lchild);
		swap_child(T->rchild);
		BiTNode* temp;
		temp = T->rchild;
		T->rchild = T->lchild;
		T->lchild = temp;
	}
}

void nine_4_3(BiTree T) {
	//交換左右子樹-後序遍歷的思想
	swap_child(T);
	cout << "交換左右子(後序輸出):";
	LRD_DG_printTree(T);
}

遞歸路徑:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章