【分析】:关键是找到元素应该插入的位置,可以采用与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 }

 

相关文章:

  • 2022-12-23
  • 2021-09-04
  • 2021-11-04
  • 2021-08-26
  • 2021-08-14
  • 2022-01-14
  • 2021-09-18
猜你喜欢
  • 2022-02-24
  • 2022-12-23
  • 2021-05-10
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
相关资源
相似解决方案