bitree.cpp

来自「二叉树的创建 增删改查 等功能 对学习二叉树的很有帮助」· C++ 代码 · 共 39 行

CPP
39
字号
// bitree.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "tree.h"

#define SIZE 12

int main(int argc, char* argv[])
{
	CTree tree;
	tree.m_pRoot=new CTreeNode[SIZE];
	tree.m_pRoot[0].m_pLeft=&tree.m_pRoot[1];
	tree.m_pRoot[0].m_pRight=&tree.m_pRoot[2];
	tree.m_pRoot[1].m_pLeft=&tree.m_pRoot[3];
	tree.m_pRoot[1].m_pRight=&tree.m_pRoot[4];
	tree.m_pRoot[2].m_pLeft=&tree.m_pRoot[5];
	tree.m_pRoot[2].m_pRight=&tree.m_pRoot[6];
	tree.m_pRoot[3].m_pRight=&tree.m_pRoot[7];
	tree.m_pRoot[6].m_pLeft=&tree.m_pRoot[8];
	tree.m_pRoot[7].m_pLeft=&tree.m_pRoot[9];
	tree.m_pRoot[7].m_pRight=&tree.m_pRoot[10];
	tree.m_pRoot[9].m_pRight=&tree.m_pRoot[11];

	for(long i=0;i<SIZE;i++)
		tree.m_pRoot[i].m_data=i+1;

	tree.CheckNodeNum(tree.m_pRoot);

	cout<<tree.GetTreeNodeNum()<<endl;

	cout<<tree.CheckDepth(tree.m_pRoot)<<endl;
	for(i=0;i<SIZE;i++)
		tree.m_pRoot[i].Clear();

	delete [] tree.m_pRoot;
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?