diff --git a/src/Containers-AVL-Tree/CTAVLAbstractNode.class.st b/src/Containers-AVL-Tree/CTAVLAbstractNode.class.st index 776407e..864c1f4 100644 --- a/src/Containers-AVL-Tree/CTAVLAbstractNode.class.st +++ b/src/Containers-AVL-Tree/CTAVLAbstractNode.class.st @@ -119,12 +119,6 @@ CTAVLAbstractNode >> isLeaf [ ^ self subclassResponsibility ] -{ #category : 'testing' } -CTAVLAbstractNode >> isNilNode [ - - ^ false -] - { #category : 'accessing' } CTAVLAbstractNode >> parent [ diff --git a/src/Containers-AVL-Tree/CTAVLNode.class.st b/src/Containers-AVL-Tree/CTAVLNode.class.st index 232b2b5..f1112b2 100644 --- a/src/Containers-AVL-Tree/CTAVLNode.class.st +++ b/src/Containers-AVL-Tree/CTAVLNode.class.st @@ -44,8 +44,11 @@ CTAVLNode >> balanceFactor [ { #category : 'accessing' } CTAVLNode >> children [ - - ^ { left . right } + | validChildren | + validChildren := OrderedCollection new: 2. + left isEmpty ifFalse: [ validChildren add: left ]. + right isEmpty ifFalse: [ validChildren add: right ]. + ^ validChildren asArray ] { #category : 'accessing' } @@ -175,10 +178,10 @@ CTAVLNode >> left: aNode [ { #category : 'copying' } CTAVLNode >> postCopy [ - super postCopy. - - left isNilNode ifFalse: [ left := left copy ]. - right isNilNode ifFalse: [ right := right copy ] + super postCopy. + + left := left copy. + right := right copy ] { #category : 'enumerating' } diff --git a/src/Containers-AVL-Tree/CTAVLTree.class.st b/src/Containers-AVL-Tree/CTAVLTree.class.st index d53e7d4..d2933fc 100644 --- a/src/Containers-AVL-Tree/CTAVLTree.class.st +++ b/src/Containers-AVL-Tree/CTAVLTree.class.st @@ -40,14 +40,13 @@ CTAVLTree >> addAll: aCollection [ CTAVLTree >> allChildren [ | allNodes queue currentNode | allNodes := OrderedCollection new. - self root isNilNode ifTrue: [ ^ allNodes ]. + self root isEmpty ifTrue: [ ^ allNodes ]. queue := OrderedCollection with: self root. [ queue isNotEmpty ] whileTrue: [ currentNode := queue removeFirst. allNodes add: currentNode. - currentNode left isNilNode ifFalse: [ queue add: currentNode left ]. - currentNode right isNilNode ifFalse: [ queue add: currentNode right ] + queue addAll: currentNode children ]. ^ allNodes @@ -231,8 +230,8 @@ CTAVLTree >> last [ { #category : 'copying' } CTAVLTree >> postCopy [ - super postCopy. - root := root copy. + super postCopy. + root := root copy. ] { #category : 'enumerating' }