- Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathRedBlackTreeNode.cs
86 lines (72 loc) · 2.52 KB
/
RedBlackTreeNode.cs
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
namespaceDataStructures.Trees
{
/// <summary>
/// Red-Black Tree Node.
/// </summary>
publicclassRedBlackTreeNode<TKey>:BSTNode<TKey>whereTKey:System.IComparable<TKey>
{
privateRedBlackTreeColors_color;
/// <summary>
/// CONSTRUCTORS
/// </summary>
publicRedBlackTreeNode():this(default(TKey),0,null,null,null){}
publicRedBlackTreeNode(TKeyvalue):this(value,0,null,null,null){}
publicRedBlackTreeNode(TKeyvalue,intheight,RedBlackTreeNode<TKey>parent,RedBlackTreeNode<TKey>left,RedBlackTreeNode<TKey>right)
{
base.Value=value;
Color=RedBlackTreeColors.Red;
Parent=parent;
LeftChild=left;
RightChild=right;
}
publicvirtualRedBlackTreeColorsColor
{
get{returnthis._color;}
set{this._color=value;}
}
publicnewRedBlackTreeNode<TKey>Parent
{
get{return(RedBlackTreeNode<TKey>)base.Parent;}
set{base.Parent=value;}
}
publicnewRedBlackTreeNode<TKey>LeftChild
{
get{return(RedBlackTreeNode<TKey>)base.LeftChild;}
set{base.LeftChild=value;}
}
publicnewRedBlackTreeNode<TKey>RightChild
{
get{return(RedBlackTreeNode<TKey>)base.RightChild;}
set{base.RightChild=value;}
}
/******************************************************************************/
/// <summary>
/// Returns if this node is colored red.
/// </summary>
publicvirtualboolIsRed
{
get{returnColor==RedBlackTreeColors.Red;}
}
/// <summary>
/// Checks whether this node is colored black.
/// </summary>
publicvirtualboolIsBlack
{
get{returnColor==RedBlackTreeColors.Black;}
}
/// <summary>
/// Returns the sibling of this node.
/// </summary>
publicvirtualRedBlackTreeNode<TKey>Sibling
{
get{return(this.Parent==null?null:(this.IsLeftChild?this.Parent.RightChild:this.Parent.LeftChild));}
}
/// <summary>
/// Returns the grandparent of this node.
/// </summary>
publicvirtualRedBlackTreeNode<TKey>GrandParent
{
get{return(this.Parent==null?null:this.Parent.Parent);}
}
}
}