求助!!!
  • 板块学术版
  • 楼主answerking
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/8/30 11:33
  • 上次更新2023/11/3 00:22:52
查看原帖
求助!!!
916779
answerking楼主2023/8/30 11:33
#include<iostream>
#include<string>
#include<cstring>
using namespace std; 

const int N=1e5+10;
char tree[N];
int pos;
string data="ABD##E##C#F##";

void build(int root){//建立树 
	if(data[pos]=='#'){
		pos++;
		return;
	}
	if(pos>data.size())return;
	tree[root]=data[pos++];
	build(root<<1);
	build(root<<1|1);
}
void preOrd(int root){//前序遍历 
	if(!tree[root])return;
	cout<<tree[root];
	preOrd(root<<1);
	preOrd(root<<1|1);
}
void midOrd(int root){
	if(!tree[root])return;
	midOrd(root<<1);
	cout<<tree[root];
	midOrd(root<<1|1);
}
void houOrd(int root){
	if(!tree[root])return;
	houOrd(root<<1);
	houOrd(root<<1|1);
	cout<<tree[root];
}
int main(){
	memset(tree,0,sizeof(tree));
	build(1);
	cout<<"前序遍历:"<<endl;
	preOrd(1);
	cout<<endl<<"中序遍历:"<<endl;
	midOrd(1);
	cout<<endl<<"后序遍历:"<<endl;
	houOrd(1);
	return 0;
}

如题 23,29,35行的“if(!tree[root])return;”是什么意思

2023/8/30 11:33
加载中...