forked from pharo-containers/Container-AVL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCTAVLNilNode.class.st
More file actions
168 lines (118 loc) · 2.69 KB
/
CTAVLNilNode.class.st
File metadata and controls
168 lines (118 loc) · 2.69 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
"
I represent an empty node in an AVL Tree using the Null Object pattern.
I provide default 'do nothing' behavior for all tree operations, eliminating the need for nil checks throughout the tree algorithms. This makes the code cleaner and prevents null pointer errors.
When elements are added to me, I create and return a new CTAVLNode containing the element, effectively growing the tree. I maintain height 0 and am always balanced
"
Class {
#name : 'CTAVLNilNode',
#superclass : 'CTAVLAbstractNode',
#category : 'Containers-AVL-Tree',
#package : 'Containers-AVL-Tree'
}
{ #category : 'adding' }
CTAVLNilNode >> addChild: anObject [
^ CTAVLNode new
contents: anObject;
parent: self parent;
yourself
]
{ #category : 'accessing' }
CTAVLNilNode >> balanceFactor [
^ 0
]
{ #category : 'accessing' }
CTAVLNilNode >> contents [
^ nil
]
{ #category : 'accessing' }
CTAVLNilNode >> contents: anObject [
"Do nothing for nil node"
]
{ #category : 'copying' }
CTAVLNilNode >> copy [
^ self class new
]
{ #category : 'enumerating' }
CTAVLNilNode >> elementsFrom: min to: max into: aCollection [
"Do Nothing for Nil Node"
]
{ #category : 'enumerating' }
CTAVLNilNode >> elementsGreaterThan: anObject into: aCollection [
"Do Nothing for Nil Node"
]
{ #category : 'enumerating' }
CTAVLNilNode >> elementsLessThan: anObject into: aCollection [
"Do Nothing for Nil Node"
]
{ #category : 'searching' }
CTAVLNilNode >> findMax [
^ nil
]
{ #category : 'searching' }
CTAVLNilNode >> findMaxNode [
^ self
]
{ #category : 'searching' }
CTAVLNilNode >> findMin [
^ nil
]
{ #category : 'searching' }
CTAVLNilNode >> findMinNode [
^ self
]
{ #category : 'accessing' }
CTAVLNilNode >> height [
^ 0
]
{ #category : 'enumerating' }
CTAVLNilNode >> inOrderDo: aBlock [
"Do Nothing for Nil Node"
]
{ #category : 'testing' }
CTAVLNilNode >> isEmpty [
^ true
]
{ #category : 'testing' }
CTAVLNilNode >> isLeaf [
^ false
]
{ #category : 'testing' }
CTAVLNilNode >> isNilNode [
^ true
]
{ #category : 'enumerating' }
CTAVLNilNode >> postOrderDo: aBlock [
"Do Nothing for Nil Node"
]
{ #category : 'enumerating' }
CTAVLNilNode >> preOrderDo: aBlock [
"Do Nothing for Nil Node"
]
{ #category : 'searching' }
CTAVLNilNode >> predecessorOf: anObject [
^ nil
]
{ #category : 'removing' }
CTAVLNilNode >> removeValue: anObject [
^ self
]
{ #category : 'accessing' }
CTAVLNilNode >> search: anObject [
^ nil
]
{ #category : 'accessing' }
CTAVLNilNode >> size [
^ 0
]
{ #category : 'searching' }
CTAVLNilNode >> successorOf: anObject [
^ nil
]
{ #category : 'validation' }
CTAVLNilNode >> validateAsRoot [
^ true
]
{ #category : 'validation' }
CTAVLNilNode >> validateWithMin: min max: max [
^ true
]