west 提交的代码
提交时间:2022年4月23日 20:56 语言:C++运行时间:0ms占用内存:140K
运行状态: Accepted
题目:二叉树遍历1161

大会员可查看代码,点此开通大会员

                
                    #include<cstdio>
#include<stdlib.h>
#include<string.h>
char temp[120];
bool flag = false;
int nlen;
int next;
typedef struct node
{
char nValue;
	node *pLeft;
	node *pRight;
}BinaryTree;
void CreateBinaryTree(BinaryTree**pTree)
{
	if(next>=nlen)return;
	char c = temp[next++];
	if(c=='#')return;
	*pTree  =(BinaryTree*)malloc(sizeof(BinaryTree));
	(*pTree)->nValue = c;
	(*pTree)->pLeft = NULL;
	(*pTree)->pRight = NULL;
	CreateBinaryTree(&((*pTree)->pLeft));
	CreateBinaryTree(&((*pTree)->pRight));
}
void Per(BinaryTree*p)
{
	if(p==NULL)return;
	printf("%c ",p->nValue);
	Per(p->pLeft);
	Per(p->pRight);
}
void Mid(BinaryTree*p)
{
	if(p==NULL)return;
	Mid(p->pLeft);
	printf("%c ",p->nValue);
	Mid(p->pRight);
}
int main()
{
	while(~scanf("%s",temp))
	{
	next = 0;
	nlen = strlen(temp);
	BinaryTree *pRoot =NULL;
	CreateBinaryTree(&pRoot);
	Mid(pRoot);
	puts("");
	}
	return 0;
}