文章

71

粉丝

97

获赞

5

访问

16.3k

头像
判断二叉树是否对称 55%
我要提问
发布于2024年3月18日 18:39
阅读数 166

#include<iostream>
#include<cstring>
#include<string>
#include<queue>
using namespace std;

typedef struct Tnode {
    char data;
    struct Tnode* lchild, * rchild;
}Tnode, * Tree;

void createNode(Tree &T,char c) {
    T = (Tnode*)malloc(sizeof(Tnode));
    T->data = c;
    T->lchild = NULL;
    T->rchild = NULL;
}

void createTree(Tree &T,string str,int& position) {
    queue < Tree> q;
    if (str[position] != '#') {
    
        createNode(T,str[position++]);
        q.push(T);
    }
    while (!q.empty()) {
        Tree current = q.front();
        if (str[position] != '#') {
     &nb...

登录查看完整内容


登录后发布评论

2 条评论
snake
2024年3月18日 20:58

ABC#D####

赞(0)

DestinyCares+++ : 回复 snake: 好的 当遍历到#时position忘加一了

2024年3月20日 13:46