-
Notifications
You must be signed in to change notification settings - Fork 3
/
TreeNode.hh
87 lines (68 loc) · 1.76 KB
/
TreeNode.hh
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// Copyright 2009-2017 M. Shulhan (ms@kilabit.info). All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef _LIBVOS_TREENODE_HH
#define _LIBVOS_TREENODE_HH 1
#include "BNode.hh"
namespace vos {
enum _node_attr {
RBT_IS_RED = 1
, RBT_IS_BLACK = 2
};
//
// `TreeNode` implement node for tree data structure, with
// - two pointers to child nodes: `_left` and `_right`,
// - one pointer to parent node,
// - and one pointer to the `_item` that its contain,
// - and one field for node attribute `_attr`.
//
class TreeNode : public BNode {
public:
explicit TreeNode(Object* item);
virtual ~TreeNode();
void detach();
void set_attr(int x);
void set_attr_to_red();
void set_attr_to_black();
int get_attr();
void swap_attr(TreeNode* node);
int have_attr(int x);
int is_red();
int is_black();
int is_left_red();
int is_right_red();
using BNode::set_left;
void set_left(TreeNode* node);
TreeNode* get_left();
using BNode::set_right;
void set_right(TreeNode* node);
TreeNode* get_right();
void set_parent(TreeNode* node);
TreeNode* get_parent();
TreeNode* get_grand_parent();
int have_no_childs();
int have_red_childs();
int have_black_childs();
void set_childs_attr(int x);
void set_childs_attr_to_red();
void set_childs_attr_to_black();
using BNode::insert_left;
void insert_left(TreeNode* node);
using BNode::insert_right;
void insert_right(TreeNode* node);
const char* chars();
int _attr;
TreeNode* _left;
TreeNode* _right;
TreeNode* _top;
static int CMP(TreeNode* x, TreeNode* y);
static const char* __cname;
private:
TreeNode(const TreeNode&);
void operator=(const TreeNode&);
};
} // namespace vos
#endif // _LIBVOS_TREENODE_HH
// vi: ts=8 sw=8 tw=78: