The binary sorting number is either an empty tree or a binary tree of the following nature:
(1) If the left subtree exists, the data of all nodes on the left subtree is smaller than that of the root node.
(2) if it has a right subtree, the data of all nodes on the right subtree is greater than that of the root node.
(3) The left and right sub-trees are a binary sorting tree.
In this way, when searching, starting from the root node, if the element to be searched is smaller than the root node, find its left subtree; otherwise, find the right subtree.
For example, data:
The Code is as follows:
1 # include <stdio. h> 2 # define arraylen 10 3 int source [] = {10, 25,}; 4 typedef struct BST 5 {6 int data; 7 struct BST * left; 8 struct BST * right; 9} bstree; 10 11 // insert node 12 Void insertbst (bstree * t, int key) to the binary sorting tree) {13 bstree * P, * parent, * head; 14 15 if (! (P = (bstree *) malloc (sizeof (bstree *) {16 printf ("error: malloc error"); 17 exit (0 ); 18} 19 20 p-> DATA = key; 21 p-> left = p-> right = NULL; 22 23 head = T; 24 while (head) {25 parent = head; 26 if (Key