Home > Back-end >  Why should create a binary tree using the secondary pointer?
Why should create a binary tree using the secondary pointer?

Time:10-26

Struct TreeNode {
Char data;
Left struct TreeNode * and * right;
};
//in accordance with the preorder traversal
create a binary treeVoid A (struct TreeNode * * root)
{
char c;

The scanf (" % c ", & amp; C);
If (c==' ') {
* root=NULL;
}
The else {
* root=malloc (sizeof (struct TreeNode));
(* root) - & gt; Data=https://bbs.csdn.net/topics/c;
A (& amp; (* root) - & gt; Left);
A (& amp; (* root) - & gt; Right);
}
}

Struct TreeNode * B (struct root TreeNode *)
{
char c;

The scanf (" % c ", & amp; C);
If (c==' ') {
The root=NULL;
}
The else {
Root=malloc (sizeof (struct TreeNode));
Root - & gt; Data=https://bbs.csdn.net/topics/c;
Root - & gt; Left=B (root - & gt; Left);
Root - & gt; Right=B (root - & gt; Right);
}
Return the root;
}
// function is wrong?
Void (C struct root TreeNode *)
{
char c;

The scanf (" % c ", & amp; C);
If (c==' ') {
The root=NULL;
}
The else {
Root=malloc (sizeof (struct TreeNode));
Root - & gt; Data=https://bbs.csdn.net/topics/c;
C (root - & gt; Left);
C (root - & gt; Right);
}
}
1. The above three functions is to create A binary tree, the difference between the functions A and B?
2. Why the function is to use A secondary pointer and pointer to function only need B level?
3. The function C is wrong? Why function B can use the primary pointer is right?
  • Related