文章

37

粉丝

67

获赞

3

访问

9.9k

头像
二叉树的建立和遍历 题解:代码如下:
P1109 同济大学机试题
发布于2024年3月8日 12:13
阅读数 422

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
//全局变量
string str;
int len, cnt = 0,nums=0;
struct node {
    char ch;
    struct node* left,*right;
};
struct node* createTree(struct node* T) {//创建树
    if (str[cnt] == ' ') {
        cnt++;
    }
    if (str[cnt] == '0' || cnt == len) {
        cnt++;
        return NULL;
    }
    if (T == NULL) {
        T = (struct node*)malloc(sizeof(struct node));
        T->ch = str[cnt++];
        T->left = NULL;
        T->right = NULL;
        T->left = createTree(T->left);
     &n...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发