首页 > 编程语言 > 详细

c++二叉搜索树

时间:2018-08-20 18:25:51      阅读:289      评论:0      收藏:0      [点我收藏+]
1 typedef struct Node *Tree;
2 struct Node
3 {
4     int data;
5     Tree left, right;
6 };

插入:

 1 int main()
 2 {
 3     cin >> N;
 4     Tree root = NULL;
 5     for (j = 0; j < N; j++)
 6     {
 7         cin >> t;
 8         root = insert(root, t);
 9     }
10 }
11 
12 Tree insert(Tree T, int data)
13 {
14     if (T == NULL)
15     {
16         T = new Node;
17         T->data = data;
18         T->left = T->right = NULL;
19     }
20     else if (data < T->data)
21         T->left = insert(T->left, data);
22     else
23         T->right = insert(T->right, data);
24     return T;
25 }

 

c++二叉搜索树

原文:https://www.cnblogs.com/lxc1910/p/9506968.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!