示例#1
0
int main(int argc, char *argv[])
{
	int compareResult = FALSE;
	int count = 0;
	BinTree *pBinTree = NULL, *pCopyBinTree = NULL;

	pBinTree = createExampleBinTree();
	printf("이진 트리 원본:\n");
	displayBinTree(pBinTree);

	pCopyBinTree = copyBinTree(pBinTree);
	printf("이진 트리 복사본:\n");
	displayBinTree(pCopyBinTree);

	compareResult = equalBinTree(pBinTree, pCopyBinTree);
	printf("\n이진 트리 비교 결과: (%d)\n", compareResult);

	count = getNodeCountBT(pBinTree);
	printf("\n이진 트리 노드 개수: %d\n", count);

	count = getLeafNodeCountBT(pBinTree);
	printf("\n이진 트리 단말 노드 개수: %d\n", count);

	count = getHeightBT(pBinTree);
	printf("\n이진 트리의 높이: %d\n", count);

	deleteBinTree(pBinTree);
	deleteBinTree(pCopyBinTree);
	return 0;
}
示例#2
0
void deleteBinTree(NodeOfTree *root)
{
	if (root == nullptr)
	{
		delete root;
		return;
	}
	if (root->left != nullptr)
	{
		deleteBinTree(root->left);
	}
	if (root->right != nullptr)
	{
		deleteBinTree(root->right);
	}
	delete root;
}