文章

15

粉丝

0

获赞

62

访问

3.6k

头像
判断二叉树是否对称 题解:
P1551 东北大学机试题
发布于2026年3月21日 19:26
阅读数 161

#include<bits/stdc++.h>
using namespace std;

typedef struct node{
    char data;
    struct node *lchild, *rchild;
}*BitTree;

bool isSym(BitTree left, BitTree right){
    if(left == NULL && right == NULL) return true;
    if(left == NULL || right == NULL) return false;
    return isSym(left -> lchild, right -> rchild) && isSym(left -> rchild, right -> lchild);
}

int main(){
    string s;
    while(cin >> s){
        if(s.empty() || s[0] == '#'){
            cout << "YES" << endl;
            continue;
        }
        int n = s.length();
        BitTree root = new node();
 ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发