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++树模板-创新互联
网站地址:https://www.cdcxhl.com/article20/dopeco.html

成都网站建设公司_创新互联,为您提供电子商务网站设计公司外贸网站建设域名注册搜索引擎优化移动网站建设

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

绵阳服务器托管