@[Feuw](/user/551088) 你 `new` 了吗
by Ruiqun2009 @ 2022-11-20 10:57:36
@[Ruiqun2009](/user/589895) 加了,但似乎没起作用
by FincheuwYggdrasil @ 2022-11-20 11:00:45
@[Feuw](/user/551088) 记得在 `BinaryTree` 的构造函数哪里给 `Val` 设定初值
by Ruiqun2009 @ 2022-11-20 11:03:34
@[Ruiqun2009](/user/589895) 请问怎么定?
by FincheuwYggdrasil @ 2022-11-20 11:04:42
@[Feuw](/user/551088) 这样的构造函数:
```cpp
BinaryTree::BinaryTree(){
Val='*';
Left=Right=nullptr;
}
```
只要对 `Val` 进行改变了就可以
by Ruiqun2009 @ 2022-11-20 11:07:08
@[Ruiqun2009](/user/589895) 请问是这样吗
```cpp
#include<bits/stdc++.h>
using namespace std;
struct BinaryTree{
char Val;
BinaryTree* Left;
BinaryTree* Right;
BinaryTree(){
Val = '*';
Left = Right = nullptr;
}
};
BinaryTree* root = new BinaryTree;
int cs;
char r,m,l;
void LOscanf(BinaryTree* root)
{
queue<BinaryTree*>q;
q.push(root);
while(!q.empty())
{
BinaryTree* nr = q.front();
cin >> m >> r >> l;
nr->Val = m;
nr->Left->Val = l;
nr->Right->Val = r;
q.pop();
if(nr->Left->Val != '*')
q.push(nr->Left);
if(nr->Right->Val != '*')
q.push(nr->Right);
}
}
void POprintf(BinaryTree* root)
{
printf("%c",root->Val);
if(root->Left->Val != '*')
POprintf(root->Left);
if(root->Right->Val != '*')
POprintf(root->Right);
}
int main()
{
scanf("%d",&cs);
LOscanf(root);
POprintf(root);
return 0;
}
```
by FincheuwYggdrasil @ 2022-11-20 11:09:45
@[Feuw](/user/551088) 差不多。
应该是算法有问题,只能获得 $30$ 分。
by Ruiqun2009 @ 2022-11-20 11:10:46
@[Ruiqun2009](/user/589895) 好的,谢谢
by FincheuwYggdrasil @ 2022-11-20 11:12:51