# Include <cstdio> <br/> # include <string. h> <br/> # include <algorithm> <br/> # include <stdlib. h> <br/> # include <iostream> <br/> using namespace STD; <br/> struct node <br/> {int val; <br/> node * left; <br/> node * right; <br/> node () <br/>{}< br/> node (int xx) <br/>{< br/> val = xx; left = right = NULL; <br/>}</P> <p>} tree; <br/> void build (node * tree, int X) // The process of building a tree is the process of Binary Search <br/>{</P> <p> If (tree-> Val> X) <br/>{< br /> If (tree-> left = NULL) <br/> tree-> left = new node (X ); <br/> else <br/> build (tree-> left, X ); </P> <p >}< br/> else if (tree-> Val <= X) <br/>{< br/> If (tree-> right = NULL) <br/> tree-> right = new node (X ); <br/> else <br/> build (tree-> right, X ); </P> <p >}< br/> void inorder (node * tree) <br/>{< br/> If (tree! = NULL) <br/>{< br/> inorder (tree-> left); <br/> printf ("% d", tree-> Val ); <br/> inorder (tree-> right); <br/> // printf ("% d", tree-> Val ); <br/>}< br/> // void postorder (node * tree) <br/> // {<br/> // If (tree! = NULL) <br/> // {<br/> // postorder (tree-> left ); <br/> // postorder (tree-> right); <br/> // Delete tree; <br/> //} <br/> int bsearch (node * tree, int key) // this search is a binary search process <br/>{< br/> If (tree = NULL) <br/> return-1; // indicates that no such data exists; search failed <br/> else <br/> {<br/> If (tree-> val = Key) // search successful <br/> return key; <br/> else if (tree-> Val> key) <br/> {<br/> bsearch (tree-> left, key ); <br/>}< br/> else if (tree-> Val <key) <br/>{< br/> bsearch (tree-> right, key ); <br/>}< br/> int main () <br/>{< br/> int X; <br/> int N; <br/> CIN> X; <br/> tree. val = x; <br/> n --; <br/> while (n --) <br/>{< br/> CIN> X; <br/> build (& tree, x); <br/>}< br/> inorder (& tree); // It is already sorted; <br/> printf ("\ n"); <br/> // postorder (& tree); // release the memory <br/> printf ("\ n "); <br/> cout <"Hello word" <Endl; <br/> return 0; <br/>}
The binary sorting tree, the binary search tree, And the Binary Search Tree refer to the same thing. They used to be confused by these concepts. Now they finally understand, the line segment tree is also a kind of deformation of the Binary Decision Tree. Therefore, it is a basic requirement to master the binary decision tree. In the future, there will be a lot of magical data structures in the binary decision tree, which has a long way to go;