重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

C++树模板-创新互联

构建树:

慈利ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:13518219792(备注:SSL证书合作)期待与您的合作!
typedef struct Node
{int data;
	Node *lchild;
	Node *rchild;
}Node;
class Tree
{	public:
		Node *root;
		Tree(int data);
		Node *maketree(Node *father,int data,int side);
		
};
Tree::Tree(int data)
{Node *newnode=new Node;
	root=newnode;
	root->data=data;
	root->lchild=NULL;
	root->rchild=NULL; 
}
Node *Tree::maketree(Node *father,int data,int side)
{Node *newnode=new Node;
	newnode->data=data;
	newnode->lchild=NULL;
	newnode->rchild=NULL;
	if(side==0)
	{father->lchild=newnode; 
	} 
	else
	{father->rchild=newnode; 
	}
	return newnode;
}

前序遍历:

void front_display(Node *start)
{cout<data<<' ';
	if(start->lchild)
	{front_display(start->lchild);
	}
	if(start->rchild)
	{front_display(start->rchild);
	}
}

中序遍历:

void middle_display(Node *start)
{	if(start->lchild)
	{middle_display(start->lchild);
	}
	cout<data<<' ';
	if(start->rchild)
	{middle_display(start->rchild);
	}
}

后序遍历:

void last_display(Node *start)
{if(start->lchild)
	{last_display(start->lchild);
	}
	if(start->rchild)
	{last_display(start->rchild); 
	}
	cout<data<<' ';
}

未经允许,不得转载!

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


分享标题:C++树模板-创新互联
网址分享:http://cqcxhl.com/article/dopeco.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP