-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSplayTree.h
62 lines (51 loc) · 1.08 KB
/
SplayTree.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
57
58
59
#ifndef SPLAYTREE_H
#define SPLAYTREE_H
#include <iostream>
#include <iomanip>
using namespace std;
typedef struct SplayNode *TreeNode; // 节点重命名,方便操作
/* 伸展树节点
* 储存数据:
* Element:储存元素
* Left:左子树节点
* Right:右子树节点
*/
struct SplayNode {
int Element;
TreeNode Left;
TreeNode Right;
};
/* SplayTree类
* 接口:
* MakeEmpty:置空函数,将树结构置空
* Splay:伸展函数,将目标节点展开
* Find:查找函数,查找目标元素
* Insert:插入函数,插入目标元素
* Remove:删除函数,删除目标元素
* Display:展示函数,展示树中的信息
*/
class SplayTree
{
public:
// 构造函数
SplayTree();
// 析构函数
~SplayTree();
// 接口函数
void MakeEmpty();
void Splay(const int);
int Find(const int);
void Insert(const int);
void Remove(const int);
void Display();
private:
// 辅助功能函数
void Splay(const int, TreeNode &);
void MakeEmpty(TreeNode);
void Display(const TreeNode&,const int, const int);
void SingleRotateWithRight(TreeNode &);
void SingleRotateWithLeft(TreeNode &);
TreeNode Root; // 储存根节点
TreeNode NullNode; // 储存空标志节点
};
#endif // !SPLAYTREE_H