Home > Back-end >  Create confusion in the binary tree, and solutions
Create confusion in the binary tree, and solutions

Time:09-26

#include
#include
#include
#include
#include
using namespace std;
Typedef char ElemType;
Typedef struct BtNode
{
BtNode * leftchild;
BtNode * rightchild;
ElemType data;
} BtNode, * BinaryTree;
//buy node
BtNode * Buynode ()
{
BtNode * p=(BtNode *) malloc (sizeof (BtNode));
If (NULL==p) exit (1);
Memset (p, 0, sizeof (BtNode));
Return the p;
}
Void * Freenode network (BtNode * PTR)
{
Free (PTR);
}


//method a
In order to create a binary tree before//
Void * PreCreateTree (BinaryTree * PTR)
{
char ch;
Cin> & gt; ch;
If (ch!='#' | | PTR!=NULL)
{
* PTR=Buynode ();
(* PTR) - & gt; data=https://bbs.csdn.net/topics/ch;
PreCreateTree (& amp; (* PTR) - & gt; Leftchild);
PreCreateTree (& amp; (* PTR) - & gt; Rightchild);
}
}
Int main ()
{
BinaryTree root=NULL;
PreCreateTree (& amp; Root);
}



One parameter is * PTR, why method is not PTR? Make function * and & amp; * PTR is the specification?

PTR to root is a pointer, also can have the same effect, and not so complicated,

The above code how to create an empty binary tree?

CodePudding user response:

1. Use * PTR, which is in front of you pass by the & amp; Root, if direct root, the main () inside the root will not change, this is the content of the pointer to the
2. The principle of binary tree, you can see you clearly

CodePudding user response:

reference 1/f, wu * * reply:
1. Use * PTR, is in front of you pass the cords & amp; Root, if direct root, the main () inside the root will not change, this is the content of the pointer to the
2. The principle of binary tree, you can see you clearly

Thanks, see some very good explanation behind solved the problem 1, have a lot of methods, to create a binary tree are about the same, also see some,
  • Related