Just opened a head, I have to say goodbye - in the tree, except for the binary tree, others have not yet speaking. Why can you summarize it? Because the two basic purposes have been involved in the tree, if B , B-, if you don't mention the search, if you are a winner tree, you can't not mention sorting. To this end, this part is placed behind. The efforts I have made in front, just let you have a basic concept, when do you remember to use trees.
Two basic uses of the tree can be metaphor for substances and spirit.
One use is to do data storage, store data with tree structure - directory, family score, etc. In order to actually store nonlinear tree structures (memory, disk), there must be a structure that indicates the tree. Therefore, as long as it can distinguish roots and subtots, the trees can take various methods to store - forklin sheets, left children - right brothers two-fork tables, generalized forms, multi-dimensional arrays. Since the needs of operation, the storage method is not randomly selected. For example, in the implementation of the collections, choose a double-linked list.
One use is to be a logical judgment, and a noun is often heard at this time. The most commonly used structure is a binary tree, a child represents True, a child represents False. About a fork decision tree, there is an example is the full solution of 8 Queen - this Lio Goss is wrong (a total of 92 decisions, Gauss is the first 76-story solution), we are more than Gauss, but we will Let Computer it work.
Just like the philosophical circle is also entangled in material and spiritual origins, it is actually the same here. In some cases, you can't distinguish whether it is to be used as a use or as a judgment, such as searching a tree, which is stored in data, but also implies judgment.
The tree is more basic and is more commonly used in compared with the drawings. You can don't know how to ask for the shortest path, but you will be a tree every moment - see the folder in your computer.
Finally, a procedure with all the solutions to N Queens.
#include
#define n 8
INT LAYOUT [N]; // Layout
INT key = 0;
INT JUDGE (int Row, int co) // Determines if (Row, COL) is put down
{
INT I;
For (i = 0; i { IF (Layout [i] == COL) Return 0; // Same column IF (i - layout [i] == row - col) return 0; // Same primary diagonal IF (i layout [i] == ROW COL) Return 0; // Same pair diagonal } Return 1; } Void Lay (int Row) // On Row Queen { INT I; IF (row == n) // puts N Queen output layout { Printf ("/ n% 02d", kEY); For (i = 0; i } Else { For (i = 0; i { Layout [ROW] = I; IF (Judge (Row, I)) LAY (ROW 1); } } } int main () { Lay (0); Return 0; }