Programmer account notes (14)

xiaoxiao2021-03-06  102

Today, continue to talk two-forked trees, an important operation of the tree is traversal. The so-called traversal is to output all the nodes, and the binary tree is different from the tree, because the binary tree is characterized by the left and right sub-trees, all of which have another traversal method, is the order. These traverses are also very simple, the most important thing is to look at the front of the root traversal. Here, see the 14th day of these color circles, representatives, as a tree, all we know that its rules can be written, the program is also very simple, as follows:

OUT1 (BTREE * T) / * pre-sequence traversal * /

{

Printf ("% D", T-> DATA);

OUT1 (T-> LEFT);

OUT1 (T-> Right);

}

OUT2 (BTREE * T) / * Sub-sequence traversal * /

{

OUT2 (T-> LEFT);

Printf ("% D", T-> DATA);

OUT2 (T-> Right);

}

OUT3 (BTREE * T) / * sequence traversal * / {OUT3 (T-> LEFT); OUT3 (T-> Right); Printf ("% d", t-> data);} The above three traversal is not It is very simple (this recursive thinks, I understand), and they are like just changing the position, we can see if the output of the pre-sequence is the first, follow the left tree to Right tree. After reading the traversal, look at the binary look tree, the binary look tree is such a tree, his left knot is smaller than the root, and the right node is greater than the left knot. There is such a nature, so his insertion is particularly good, and the method of designing this sequential traversal is particularly good, because this tree is originally sorted. Let's take a look at how the program is implemented in INSERT (BTREE * H, BTREE * P) {if (h = = null) h = p; p-> left = p-> right = null; / * Last node It must be no left and right bon trees * / else {if (P-> Data data) INSERT (H-> LEFT); if (P-> Data> H-> DATA) INSERT (H-> Right); }} It seems to be very simple, but because of the recursive to understand some ideas, see how it generates inserted to the right position, like the establishment of two-fork trees in the previous class, is also compared to his value size position position . Everyone should understand well. It is because several students in our class are more strange to the tree, can't keep up, so the teacher decided to first put the tree, in fact, there are still many knowledge of the tree, but I have to wait a row of thinking. It can continue, in fact, if I haven't seen myself before, I may really can't understand when I said it, I can't understand it. Time really used a lot of things on these trees, and there is no big effect. Teachers are also working immediately, skip this section to find this chapter. It is actually that we will always have accessible. In particular, when I learned FoxBase, I basically fell inseparable, but the lookup at that time was such a command. Now I have to make myself, I really are very fun. I used to completely encapsulated FoxBase commands. Today, I have to build it in the C language of this system to study it. The previous list and structure are used to do a database (if I have no estimation.). Said more, and immediately talk about the situation in learning. The order looks to believe that everyone knows the principle, because one of a order judgment is equal to this is the most common. I am not talking here, I will continue to talk about one, and I've been folded. Before talking about this, the teacher and we did a game, that is, he wrote a value on the paper, and we guess it in 1 to 1000. If we say the number of teachers, the teacher is too big, too small. In fact, this folding half of the primary instance has been seen in QB, and there is no difficulty. Soon, we will guess the number, and the teacher saw us and understood that we wrote a procedure. At the time, I saw that this question has been repeated and has been recursive. To do this, but I am wrong, but this is wrong, I have learned another trick. Let's take a look at my programs first, as follows: If a [] is already a value, but it is still in order.

转载请注明原文地址:https://www.9cbs.com/read-124123.html

New Post(0)