-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinary_search_tree.h
executable file
·56 lines (52 loc) · 1.28 KB
/
binary_search_tree.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* @file binary_search_tree.h
* @brief 一颗搜索树既可以作为一个字典也可以作为一个优先队列
* include the 1.Traversing Search Maxnum Minnum successor predecessor
* 2.insert and delete
* @author tmd
* @version 1.0
* @date 2016-11-21
*/
#ifndef __BIN_TREE_H__
#define __BIN_TREE_H__
typedef struct node{
int key;
struct node* left;
struct node* right;
struct node* pre;
}Node;
typedef struct tree{
struct node* root;
int count;
}Tree;
//init node
Node* bin_tree_node(int key);
//init tree
Tree* bin_tree_init();
//insert
int bin_tree_insert(Tree* tree, Node* node);
//递归
Node* bin_tree_search(Node* root, int key);
//迭代
Node* bin_tree_iter_search(Node* root, int key);
//traver maxnum minnum successor predecessor
void bin_tree_inorder(Node* root);
//maxnum
Node* maxnum(Node* root);
//minnum
Node* minnum(Node* root);
//successor后继
Node* successor(Node* aim);
//predecessor前驱
Node* predece(Node* aim);
//transplant ps:use the aim change node as the son tree root
//does not care the aim node left and right side
void bin_tree_transplant(Tree* tree, Node* node, Node* aim);
//delete
int bin_tree_delete(Tree* tree, Node* node);
//show
void shownode(Node* node);
//free the memery
//Free(Tree* tree);
//free_node(Node* node);
#endif //__BIN_TREE_H__