文章

17

粉丝

0

获赞

5

访问

1.3k

头像
二叉树的建立和遍历 题解:只看题注,没看输出要求,所以把二叉树的相关功能几乎都写了
P1109 同济大学机试题
发布于2025年5月18日 15:47
阅读数 126

#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;

//二叉树结构
typedef struct node{
    char data;
    struct node *lchild,*rchild;
}*BiTree;

//先序遍历的方式建立二叉树
void CreateBiTree(BiTree &T,const string &s,int &index){
    if(index<s.length()){
        char ch=s[index++];
        if(ch=='0')    T=NULL;
        else{
            T=new node;
            T->data=ch;
            CreateBiTree(T->lchild,s,index);
            CreateBiTree(T->rchild,s,index);
        }
    }
   &nb...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发