二叉搜索树的插入

【分析】:关键是找到元素应该插入的位置,可以采用与Find类似的方法。

 1 BinTree Insert(ElementType x,BinTree BST)
 2 {
 3   if(!BST)
 4   {
 5     BST=malloc(sizeof(struct TreeNode));
 6     BST->Data=x;
 7     BST->Left=BST-Right=NULL;
 8   }
 9   else
10   {
11     if(x>BST->Data)
12        BST->Right=Insert(x,BST->Right);
13     else if(x<BST->Data)
14       BST->Left=Insert(x,BST->Left);
15    }
16    return BST;
17 }
原文地址:https://www.cnblogs.com/cynthia-dcg/p/6755931.html