Special excitement today, getting a special early. I took the computer before I left, and of course, I didn't know if I could do this after school, because some factors in the family. However, as long as I can serve everyone, I am very happy, and there is also a sense of strong happiness. This kind of happiness is not a general family happiness. I have done it, I often ask some netizens about this matter, they all say that only you can do it, they all support me to do it. Ok, say far away, I talked about the course today.
Today's curriculum also made me aesthetically surprised, it is a tree in the data structure. Why didn't you talk about the tree without talking about the queue and stack? Will it be too fast, and we just finished the fake, some people have not concentrated the spirit to class. However, I will believe that the teacher's choice should have his reasons. Then tell some basic concepts of the tree, everyone knows that the tree is one of the nonlinear structures in the data structure. It is completely different from the list of the previously, and the list is only the front drive and the subsequent node, but the tree is not. He can have a lot of nodes, called branch nodes, and his branch node can have branch nodes. Because the concept of the tree is too much, I have to look at the book. The tree is used very widely, and the file management in our operating system is, multi-level directory. The secondary directory is like the tree tree of the tree, and there may be a lot of sub-trees in the sub-tree, the more the next level.
Let's try to define a tree structure, the general tree is very casual, all us will also draw a tree casually.
Look at the thirteenth day of the picture, one we see a node, and the top of the top is the sonic point. The previous one of the sub-nodes is the parent node, and the same level is from the brothers. We define one according to this structure, as follows: struct tree {int Data; Struct Tree * next; / * Right brother node * / struct tree * pre; / * left brothers Node * / Struct Tree * Up; / * Father Node * / struct tree * down; / * sub-node * /}; let's see how to build a tree. Struct Tree * p, * r; r = (Struct Tree *) Malloc (Struct Tree); / * Establish root node space * / r-> data = 3; / * root knot assignment * / r- > next = r-> pre = r-> Up = NULL; P = (struct tree *) malloc (Struct Tree); / * Create a second node * / r-> down = P; / * Sub nodes of root nodes are connected to new sub-nodes * / p-> DATA = 5; / * Subpoint assignment * / p-> pre = null; p-> next = (struct trees *) Malloc Sizeof (Struct Tree); P-> Next-> DATA = 2; P-> Next-> pre = P;:::: Because there is no regular node, all such establishment methods cannot be used, now Just take it out to study how a tree is established. Now talk about another tree "binary tree". Because the binary tree is compared with the general tree structure, the binary tree is more standardized and more determined, so applications are more wide than the tree. The binary tree is different from the tree, and the first binary tree can be empty, the empty binary tree has no nodes; in addition, in the binary tree, the bifurcation of the node is ordered, and the left and right sub-bifurcies. How is the binary tree established? It is very simple here because the binary tree has its regularity. Please look at the TypeDef struct bNode {int Data; struct bNode * left, * right;} btree; void creat (btree * b) {int x; btree * s; b = null DO {scanf ("% D", & x); s = (btree *) malloc (sizeof (btree)); S-> Data = X; S-> LEFT = S-> Right = NULL; Insert (B, s);}}
Void INSERT (BTREE * B, BTREE * S) {if (b == null) b = s; ELSE IF (S-DATA == B-> DATA) RETURN (); ELSE IF (S-Data
DATA) INSERT (B-> Left, S);
Else IF (S-Data> B-> DATA) INSERT (B-> Right, S);
}
This procedure only has only one tree, and it is placed (left small right). Enter the corresponding value to see the result, as shown on the thirteenth day.