⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 erchashubianli.txt

📁 数据结构中二叉树遍历算法
💻 TXT
字号:
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
#include <iostream>
using namespace std;
typedef struct node
{
	char date;
	struct node *Lchild,*Rchild;
}*bitreptr;
void CreateBtr(bitreptr &t)
{
	bitreptr p;
	char x;
	cin>>x;
	if (x=='#')
		t=NULL;
	else
	{
		p=new node;
		p->date=x;
		t=p;
		CreateBtr(t->Lchild);
		CreateBtr(t->Rchild);
	}
}
void Preorder (bitreptr p)
{
	if (p)
	{
		cout<<p->date;
		Preorder(p->Lchild);
		Preorder(p->Rchild);
	}
}
void Inorder (bitreptr p)
{
	if (p)
	{
		Inorder(p->Lchild);
		cout<<p->date;
		Inorder(p->Rchild);
	}
}
void Postorder (bitreptr p)
{
	if (p)
	{
		Postorder(p->Lchild);
		Postorder(p->Rchild);
		cout<<p->date;
	}
}
int main()
{
	bitreptr p;
	p=new node;
	cout<<"输入树的各个元素:"<<endl;
	CreateBtr(p);
	cout<<"前序遍历:";
	Preorder(p);
	cout<<endl;
	cout<<"中序遍历:";
	Inorder(p);
	cout<<endl;
	cout<<"后序遍历:";
	Postorder(p);
	cout<<endl;
	return 0;
}

⌨️ 快捷键说明

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