文章

37

粉丝

67

获赞

3

访问

8.7k

头像
二叉树(北京邮电大学) 题解:简单代码来了哦

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

struct node {
    char ch;
    struct node* left, * right;
};
string forStr,cenStr;
int len, cnt=0;


struct node* createTree(int low, int high, struct node* T) {

    if (low > high) {
        return NULL;//结束

    }
    //在中序遍历中查找对应根结点
    for (int i = low; i <= high; i++) {
        if (cenStr[i] == forStr[cnt]) {
            cnt++;
            //记录下下标
            //创建结点
            T = (struct node*)malloc(sizeof(struct node));
            T->ch = cenStr[i];
     ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发