在我的主要内容中,我已经定义了指向二叉树和二叉树的二叉树的指针:
tBSTNodePtr *tree;
tFunctionTREE *treeF;
sctructure tBSTNodePtr看起来像这样:
typedef struct tBSTNode {
string *Key;
tVariable_Prom *BSTNodeCont;
struct tBSTNode * LPtr;
struct tBSTNode * RPtr;
} tBSTNodePtr;
结构tVariable Prom
是我存储数据的数据结构。然后我有另一个树木结构:
typedef struct FunctionTREE{
string *Key;
tBSTNodePtr *StromFunkce;
struct FunctionTREE * LPtrF;
struct FunctionTREE * RPtrF;
}tFunctionTREE;
我按地址&tree
,&treeF
发送两棵树。在函数本身中,它们被定义为**tree
,**treeF
。我正在使用主二叉树**tree
,当我通过程序时,我需要将主树更改为**treeF
中树木中的一棵树,我还需要存储主树因此它可以在以后再次使用其保存的值。所以我定义了另一个二叉树来存储主树:
tBSTNodePtr *tree_tmp;
接下来我有一个搜索功能,它应该返回指向树的指针(它搜索树的树):
int FunctionSearchTREE(tBSTNodePtr **found,tFunctionTREE * RootPtr,string *K)
{
if( RootPtr != NULL)
{
int porovnani;
porovnani= strCmpString(RootPtr->Key,K);
if(porovnani > 0)
FunctionSearchTREE(found,RootPtr->RPtrF, K);
else if(porovnani < 0)
FunctionSearchTREE(found,RootPtr->LPtrF, K);
else if(porovnani == 0)
{
(*found)=(RootPtr);
return 0;
}
else return 1;
}else return 1;
}
它被称为if(FunctionSearchTREE(&odkaz2, *treeF, &Tstr) == 1) return 5;
,其中Tstr
基本上是一个结构,其中包含一个字符串,该字符串也是树的一个键,odkaz2
由tBSTNodePtr*
定义
现在出现了我迷失的部分。首先我保存我的主树
*tree_tmp = **tree
(注意tree_tmp
在函数中定义,而不是main.c,因此*
}。然后我调用FunctionSearchTREE
并将地址保存到我的主树,以便我可以使用它:
**tree = odkaz2
当我使用它时,我切换回存储的树:
**tree = *tree_tmp;
然而,当我使用树保存时,我得到了一个SegFault,或者值不存在。