- Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathRedBlackTreeMapNode.cs
87 lines (73 loc) · 2.74 KB
/
RedBlackTreeMapNode.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
87
namespaceDataStructures.Trees
{
/// <summary>
/// Red-Black Tree Map Node.
/// </summary>
publicclassRedBlackTreeMapNode<TKey,TValue>:BSTMapNode<TKey,TValue>whereTKey:System.IComparable<TKey>
{
privateRedBlackTreeColors_color;
/// <summary>
/// CONSTRUCTORS
/// </summary>
publicRedBlackTreeMapNode(TKeykey):this(key,default(TValue),0,null,null,null){}
publicRedBlackTreeMapNode(TKeykey,TValuevalue):this(key,value,0,null,null,null){}
publicRedBlackTreeMapNode(TKeykey,TValuevalue,intheight,RedBlackTreeMapNode<TKey,TValue>parent,RedBlackTreeMapNode<TKey,TValue>left,RedBlackTreeMapNode<TKey,TValue>right)
{
Key=key;
Value=value;
Color=RedBlackTreeColors.Red;
Parent=parent;
LeftChild=left;
RightChild=right;
}
publicvirtualRedBlackTreeColorsColor
{
get{returnthis._color;}
set{this._color=value;}
}
publicnewRedBlackTreeMapNode<TKey,TValue>Parent
{
get{return(RedBlackTreeMapNode<TKey,TValue>)base.Parent;}
set{base.Parent=value;}
}
publicnewRedBlackTreeMapNode<TKey,TValue>LeftChild
{
get{return(RedBlackTreeMapNode<TKey,TValue>)base.LeftChild;}
set{base.LeftChild=value;}
}
publicnewRedBlackTreeMapNode<TKey,TValue>RightChild
{
get{return(RedBlackTreeMapNode<TKey,TValue>)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>
publicvirtualRedBlackTreeMapNode<TKey,TValue>Sibling
{
get{return(this.Parent==null?null:(this.IsLeftChild?this.Parent.RightChild:this.Parent.LeftChild));}
}
/// <summary>
/// Returns the grandparent of this node.
/// </summary>
publicvirtualRedBlackTreeMapNode<TKey,TValue>GrandParent
{
get{return(this.Parent==null?null:this.Parent.Parent);}
}
}
}