大概还是递归吧
#include<iostream>
using namespace std;
#include<string>
typedef struct BitNode{
char data;
BitNode *lchild,*rchild;
}BitNode,*BiTree;
BiTree createBiTree(string str,int& pos){
if(str[pos]=='0'){
return NULL;
}
BiTree root=new BitNode;
root->data=str[pos];
++pos;
root->lchild=createBiTree(str,pos);
++pos;
root->rchild=createBiTree(str,pos);
return root;
}
void output(BiTree root){
if(root==NULL){
return;
}
cout<<root->data;
output(root->lchild);
output(root->rchild);
}
int main(){
string input;
cin>>input;
//构造二叉树
int pos=0;
BiTree root=createBiTree(input,pos);
output(root);
cout<<endl;
return 0;
}
看结果可能是过了,但是这只是单纯的背掉了而已,没啥技术含量……小白,就是这么难搞呐……