【求助】教科书式写法,我这好像输出不了案例。但是其他的可以
  • 板块P1305 新二叉树
  • 楼主wffivk
  • 当前回复2
  • 已保存回复2
  • 发布时间2021/7/23 00:47
  • 上次更新2023/11/4 13:37:15
查看原帖
【求助】教科书式写法,我这好像输出不了案例。但是其他的可以
537927
wffivk楼主2021/7/23 00:47
#include<iostream>
using namespace std;

typedef struct node
{
	char data;
	struct node *lchild,*rchild;
}Node,* tree;

int count;

void Insert(tree &bt)
{
	if(count==0)  return;
	char ch;
	cin>>ch;
	if(ch!='*')
	{
		bt=new node;
		bt->data=ch;
		bt->lchild=bt->rchild=NULL;
		Insert(bt->lchild);
		Insert(bt->rchild);
	}
	else
		bt=NULL;
	count--;
}

void print(tree bt)
{
	if(bt)
	{
		cout<<bt->data;
		if(bt->lchild) print(bt->lchild);
		if(bt->rchild) print(bt->rchild);
	}
}

int main()
{
	cin>>count;
	tree My_bt;
	Insert(My_bt);
	print(My_bt);
	return 0;
}
2021/7/23 00:47
加载中...