資源簡介
自己編寫的代碼,利用隊列的特性來 按層次需求輸出二叉樹
代碼片段和文件信息
#include
#include
#include
using?namespace?std;
struct?BTreeNode??????????????//樹節點
{
int?Value;
BTreeNode?*Left;
BTreeNode?*Right;
};
void?Add(BTreeNode?*&Rootint?x)??????//插入數值?建立二叉樹
{
if(Root==NULL)
{
BTreeNode?*p=new?BTreeNode;
p->Value=x;
p->Right=NULL;
p->Left=NULL;
Root=p;
cout< }
if(x>Root->Value?)
Add(Root->Right?x);
if(xValue?)
Add(Root->Left?x);
}
void??Print(BTreeNode?*Root)????//按層次輸出???利用容器
{
?????if(Roo
評論
共有 條評論