[size=24 px] describes the understanding of this chicken dish, 1. BiTree * l, BiTree * bt, inside the function's structure pointer variable type parameter to
Behind the function call InitList (& amp; Bt); CreateBiTree (& amp; Bt); Is such a show, so these two functions of parameter is the address
2. BiTree root, inside the function's structure variable type parameter, shown in the left function inside a function call PreOrder (bt); InOrder (bt); PostOrder (bt);
[/size]
so I want to ask: 1. BiTree * l, BiTree * bt, is to use a structure pointer variable to define a structure pointer variable * l, * the meaning of bt?;
Then BiTree root, it is to use a structure pointer variable to define the meaning of a structure variable root for?
2. Can you tell me the BiTree * l, BiTree * bt, and BiTree root on the function call what's the difference? I felt as if is a little different from o/size]
typedef struct Node//structures, the Node for structure name
{
} BiTNode, * BiTree;//is a variable structure, a structure pointer variable is
Void InitList (BiTree * l)//initializes the
{
}
Void CreateBiTree (bt) BiTree *//order first create a binary tree
{
}
Void PreOrder (BiTree root)//first sequence traversal
{
}
Void InOrder (BiTree root)//in sequence traversal
{
}
After the void PostOrder (BiTree root)//sequence traversal
{
}
Int main ()
{
BiTree bt;
InitList (& amp; Bt);
CreateBiTree (& amp; Bt);
PreOrder (bt);
InOrder (bt);
PostOrder (bt);
}
CodePudding user response:
typedef struct Node//structures, the Node for structure name
{
} BiTNode, * BiTree;//is a variable structure, a structure pointer variable//understand is wrong, here is not variable, is a type, one is structure types, one is structure pointer type
So BiTree * l is the secondary pointer, pointer is a pointer, because BiTree itself is pointer type, equivalent to BiTNode * * l, this is to can return to initialize the pointer to the function, the function change * l=XXX, the value of the function outside of the bt also affected
For example,
Int a=5
F (int * b) if you want to change within the function * b and a also affected, with first class pointer (because itself is a common variable)
The same
Int * a=NULL;
F * * b (int) to change within the function * b and a also affected, you need to use the secondary pointer (because itself is a pointer)
BiTree bt;//bt is a pointer, the equivalent of BiTNode * bt
InitList (& amp; Bt);//so here if you want to change within the function * bt, outside of the function of bt is also affected, you need to use the secondary pointer, so the parameter is BiTNode * * type, namely BiTree * type
BiTree root is the primary pointer, because traversal functions do not need to initialize a pointer, change into gaiden after * root, with the primary pointer so it is ok to
So, your question 2, the difference is
Use BiTree * l, bt BiTree * and modify * or * I bt within the function, function of bt is also affected (generally such argument is to changes in function or * * l bt)
Use BiTree root, to modify * root in function, function of bt is not affected (generally such parameter is a function does not need to modify the * root)