4
4
# color is true if it's a Red Node, else it's false
5
5
mutable struct RBTreeNode{K}
6
6
color:: Bool
7
- data:: K
8
7
leftChild:: Union{Nothing, RBTreeNode{K}}
9
8
rightChild:: Union{Nothing, RBTreeNode{K}}
10
9
parent:: Union{Nothing, RBTreeNode{K}}
10
+ data:: K
11
11
12
- RBTreeNode {K} () where K = new {K} (true , nothing , nothing , nothing , nothing )
13
-
14
- RBTreeNode {K} (d:: K ) where K = new {K} (true , d , nothing , nothing , nothing )
12
+ RBTreeNode {K} () where K = new {K} (true , nothing , nothing , nothing )
13
+ RBTreeNode {Any} () = new {Any} ( true , nothing , nothing , nothing , nothing )
14
+ RBTreeNode {K} (d:: K ) where K = new {K} (true , nothing , nothing , nothing , d )
15
15
end
16
16
17
17
RBTreeNode () = RBTreeNode {Any} ()
@@ -118,9 +118,6 @@ function right_rotate!(tree::RBTree, node_x::RBTreeNode)
118
118
node_x. parent = node_y
119
119
end
120
120
121
- node_color (color:: Bool ) = (color) ? " RED" : " BLACK"
122
- desc_node (relation, node:: RBTreeNode ) = println (" $relation is " , node. data, " color is " , node_color (node. color))
123
-
124
121
function fix_insert! (tree:: RBTree , node:: RBTreeNode )
125
122
parent = nothing
126
123
grand_parent = nothing
@@ -327,42 +324,4 @@ function Base.delete!(tree::RBTree{K}, d::K) where K
327
324
end
328
325
329
326
! y_original_color && delete_fix (tree, x)
330
- end
331
-
332
- function print_tree_inorder (tree:: RBTree )
333
- function traverse_tree (node:: RBTreeNode )
334
- if (node != tree. Nil)
335
- traverse_tree (node. leftChild)
336
- print (node. data, " " )
337
- traverse_tree (node. rightChild)
338
- end
339
- end
340
- traverse_tree (tree. root)
341
- end
342
-
343
- function print_tree (tree:: RBTree )
344
- function print_tree_helper (node:: RBTreeNode , indent, isright)
345
- if node != tree. Nil
346
- print (indent)
347
- if isright
348
- print (" R--" )
349
- indent *= " "
350
- else
351
- if (node == tree. root)
352
- print (" -->" )
353
- indent *= " "
354
- else
355
- print (" L--" )
356
- indent *= " | "
357
- end
358
-
359
- end
360
- println (node. data, " (" , node_color (node. color)[1 ], " )" )
361
- print_tree_helper (node. leftChild, indent, false )
362
- print_tree_helper (node. rightChild, indent, true )
363
- end
364
- end
365
- print_tree_helper (tree. root, " " , false )
366
- end
367
-
368
- Base. show (io:: IO , t:: RBTree ) = print_tree (t)
327
+ end
0 commit comments