C 具有空指针结构错误的二叉树

C 具有空指针结构错误的二叉树,c,C,我正在从顺序表和顺序表中构造一棵二叉树。程序从TreeNode结构正确生成二叉树。我正在尝试将它连接到树节点结构并打印出来。参见代码。我不知道如何连接树到树节点 从buildtree调用函数buildutil将返回正确的二叉树,但位于TreeNode结构。我想从树结构返回二叉树,并尝试从树结构连接temproot到trtemp #include "pch.h" #include <stdio.h> #include <stdlib.h> #include <stri

我正在从顺序表和顺序表中构造一棵二叉树。程序从TreeNode结构正确生成二叉树。我正在尝试将它连接到树节点结构并打印出来。参见代码。我不知道如何连接树到树节点

从buildtree调用函数buildutil将返回正确的二叉树,但位于TreeNode结构。我想从树结构返回二叉树,并尝试从树结构连接temproot到trtemp

#include "pch.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node
{
    int data;
    struct node * left;
    struct node * right;
} TreeNode;

typedef struct trnode 
{
    TreeNode * root;
} Tree;

  // buildtree function calls helper function buildUtil which is 
 recursive
Tree * buildTree(int * in, int * post, int size)
{

int preindex = size - 1;
Tree * trtemp = NULL;
// correctly returns the biary tree in TreeNode structure
TreeNode * temproot = buildUtil(in, post, 0, preindex, &preindex); 

*trtemp -> root = *temproot;

// Print function to print out tree. Works correctly, printing  temproot from TreeNode strucuture
preOrder(trtemp);

}
#包括“pch.h”
#包括
#包括
#包括
类型定义结构节点
{
int数据;
结构节点*左;
结构节点*右;
}三烯醇;
typedef结构trnode
{
树根;
}树木;
//buildtree函数调用辅助函数buildUtil,它是
递归的
树*buildTree(int*in,int*post,int size)
{
int preindex=大小-1;
树*trtemp=NULL;
//正确返回TreeNode结构中的双叉树
TreeNode*temproot=buildUtil(in、post、0、preindex和preindex);
*trtemp->root=*temproot;
//打印输出树的功能。工作正常,从TreeNode结构打印temproot
预订单(trtemp);
}

您的标题上写着“错误”。但是错误是什么呢?你的文字描述了你拥有的和你想要的。但问题是什么?请编辑您的问题并澄清您到底需要哪些帮助。谢谢很抱歉当我试着运行程序时。当我试图将trtemp->root设置为指向temproot时,得到“trtemp was nullptr”。我想以某种方式连接到树结构到树节点并返回trtemp。感谢您的澄清,但请不要在评论中这样做。改为编辑您的问题。谢谢
trtemp
NULL
(您将其初始化为NULL),那么您希望
trtemp->root
做什么呢?