'From VisualWorks(TM), Release 1.0 of 8 October 1992 on 4 November 1994 at 11:19:25 am'!
Object subclass: #BinaryTree
instanceVariableNames: 'nodeOrNil '
classVariableNames: ''
poolDictionaries: ''
category: 'Kernel-Objects'!
!BinaryTree methodsFor: 'printing'!
printOn: aStream
"comment stating purpose of message"
self inorderDo:
[:node | aStream nextPutAll: node value printString. aStream space.].! !
!BinaryTree methodsFor: 'traversals'!
inorderDo: aBlock
self isEmpty ifFalse:
[nodeOrNil inorder: aBlock].!
postorderDo: aBlock
self isEmpty ifFalse:
[nodeOrNil postorder: aBlock].!
preorderDo: aBlock
self isEmpty ifFalse:
[nodeOrNil preorder: aBlock].! !
!BinaryTree methodsFor: 'constructors'!
add: item
self isEmpty ifTrue:
[nodeOrNil := BinaryNode new. nodeOrNil setValue: item.]
ifFalse:
[nodeOrNil add: item].!
remove: item
self isEmpty ifTrue:
[ ^self ]
ifFalse:
[ nodeOrNil := nodeOrNil remove: item ifAbsent: [^self] ].! !
!BinaryTree methodsFor: 'predicates'!
includes: item
self isEmpty ifTrue:
[^false.]
ifFalse:
[^(nodeOrNil includes: item)]!
isEmpty
^nodeOrNil = nil.!
max
self isEmpty ifTrue:
[ ^nil ]
ifFalse:
[ ^nodeOrNil max ]! !