BinaryTree.st
author Claus Gittinger <cg@exept.de>
Fri, 18 Dec 2015 11:30:56 +0100
changeset 3666 0425141734d6
parent 3015 b85fdeed7329
child 4119 dbd20281d71f
permissions -rw-r--r--
#DOCUMENTATION class: BinaryTree comment/format in: #documentation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2770
24caf488ddc1 tree node class is private
Claus Gittinger <cg@exept.de>
parents: 2763
diff changeset
     1
"
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
     2
 COPYRIGHT (c) 2003 by eXept Software AG
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
     3
              All Rights Reserved
2770
24caf488ddc1 tree node class is private
Claus Gittinger <cg@exept.de>
parents: 2763
diff changeset
     4
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
     5
 This software is furnished under a license and may be used
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
     6
 only in accordance with the terms of that license and with the
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
     8
 be provided or otherwise made available to, or used by, any
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
     9
 other person.  No title to or ownership of the software is
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    10
 hereby transferred.
2770
24caf488ddc1 tree node class is private
Claus Gittinger <cg@exept.de>
parents: 2763
diff changeset
    11
"
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    13
3666
0425141734d6 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3015
diff changeset
    14
"{ NameSpace: Smalltalk }"
0425141734d6 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3015
diff changeset
    15
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    16
Collection subclass:#BinaryTree
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    17
	instanceVariableNames:'treeRoot sortBlock'
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    18
	classVariableNames:'DefaultSortBlock'
2776
f15140d07975 public again
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
    19
	poolDictionaries:''
f15140d07975 public again
Claus Gittinger <cg@exept.de>
parents: 2770
diff changeset
    20
	category:'Collections-Ordered-Trees'
2770
24caf488ddc1 tree node class is private
Claus Gittinger <cg@exept.de>
parents: 2763
diff changeset
    21
!
24caf488ddc1 tree node class is private
Claus Gittinger <cg@exept.de>
parents: 2763
diff changeset
    22
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    23
!BinaryTree class methodsFor:'documentation'!
2770
24caf488ddc1 tree node class is private
Claus Gittinger <cg@exept.de>
parents: 2763
diff changeset
    24
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    25
copyright
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    26
"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    27
 COPYRIGHT (c) 2003 by eXept Software AG
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    28
              All Rights Reserved
2770
24caf488ddc1 tree node class is private
Claus Gittinger <cg@exept.de>
parents: 2763
diff changeset
    29
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    30
 This software is furnished under a license and may be used
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    31
 only in accordance with the terms of that license and with the
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    33
 be provided or otherwise made available to, or used by, any
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    34
 other person.  No title to or ownership of the software is
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    35
 hereby transferred.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    36
"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    37
!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    38
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    39
documentation
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    40
"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    41
    Loosely based on the Public Domain BinaryTreeNode class from Steve Chepurny.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    42
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    43
    WARNING:
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    44
        This tree does not reorganize itself. 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    45
        Thus, its performance might degenerate to that of a linked list (see performance).
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    46
        The performance is OK, if elements are added in random order and the tree is therefore balanced.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    47
        The worst case is to add elements in order, reverseOrder or zig-zag order.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    48
        Use instances of my subclasses, which balance the tree if in doubt.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    49
3666
0425141734d6 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3015
diff changeset
    50
    EXTRA WARNING:
0425141734d6 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3015
diff changeset
    51
        the inherited storeString will generate the elements in sorted order,
0425141734d6 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3015
diff changeset
    52
        which generates exactly the generated case when read-back.
0425141734d6 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3015
diff changeset
    53
        If you use this class and need textual persistency, you should consider rewriting
0425141734d6 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3015
diff changeset
    54
        the storeOn: method, to enumerate elements in a binary segmentation fashion.
0425141734d6 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3015
diff changeset
    55
        Otherwise, please use one of the balanced trees instead,
0425141734d6 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3015
diff changeset
    56
        for example AATree or BTree.
0425141734d6 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3015
diff changeset
    57
        
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    58
    Changes:
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    59
        Changed to be Collection-protocol compatible.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    60
        Slight speedup in insert-code.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    61
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    62
    [author:]
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    63
        Steve Chepurny (original BinaryTreeNode implementation)
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    64
        Claus Gittinger (cg@alan)
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    65
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    66
    [instance variables:]
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    67
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    68
    [class variables:]
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    69
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    70
    [see also:]
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    71
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    72
"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    73
!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    74
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    75
examples
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    76
"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    77
  a degenerated tree:
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    78
                                                                [exBegin]
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    79
    |coll|
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    80
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    81
    coll := BinaryTree new.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    82
    (1 to:10) do:[:i | coll add:i].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    83
    coll addAll:(20 to:30).
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    84
    coll inspect   
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    85
                                                                [exEnd]
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    86
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    87
                                                                [exBegin]
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    88
    |tree|
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    89
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    90
    tree := self new.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    91
    tree add:'hello'.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    92
    tree add:'aaaa'.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    93
    tree add:'AAAb'.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    94
    tree add:'aaaC'.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    95
    tree add:'world'.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    96
    tree asOrderedCollection     
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    97
                                                                [exEnd]
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    98
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
    99
                                                                [exBegin]
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   100
    |tree|
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   101
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   102
    tree := self sortBlock:[:a :b | a asLowercase < b asLowercase].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   103
    tree add:'hello'.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   104
    tree add:'aaaa'.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   105
    tree add:'AAAb'.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   106
    tree add:'aaaC'.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   107
    tree add:'world'.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   108
    tree asOrderedCollection     
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   109
                                                                [exEnd]
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   110
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   111
  timing examples and benchmarks: see examples in AATree:  
2770
24caf488ddc1 tree node class is private
Claus Gittinger <cg@exept.de>
parents: 2763
diff changeset
   112
24caf488ddc1 tree node class is private
Claus Gittinger <cg@exept.de>
parents: 2763
diff changeset
   113
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   114
  A functional example of a UCB-CS61A lecture's example.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   115
  The task is to extract all values within a given range (min..max) from
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   116
  a binary tree.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   117
  The range 'function' below does this; given a binary tree, a min and max value,
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   118
      range(bst, min, max)
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   119
  returns an array of all values which are within that range.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   120
  Only the relevant branches of the binary tree are to be visited, of course.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   121
                                                                [exBegin]
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   122
    |t rangeNode range|
2770
24caf488ddc1 tree node class is private
Claus Gittinger <cg@exept.de>
parents: 2763
diff changeset
   123
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   124
    t := BinaryTree new.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   125
    t add:54; add:37; add:19; add:45; add:80; add:65; add:91; add:57.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   126
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   127
    rangeNode := [:node :min :max |
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   128
                |nodeValue leftTree rightTree left right middle|
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   129
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   130
                leftTree := node leftSubtree.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   131
                rightTree := node rightSubtree.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   132
                nodeValue := node data.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   133
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   134
                left := (leftTree notNil and:[nodeValue > min]) 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   135
                            ifTrue:[ rangeNode value:leftTree value:min value:max ]
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   136
                            ifFalse:[ #() ].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   137
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   138
                right := (rightTree notNil and:[nodeValue < max]) 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   139
                            ifTrue:[ rangeNode value:rightTree value:min value:max ]
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   140
                            ifFalse:[ #() ].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   141
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   142
                middle := (nodeValue between:min and:max)
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   143
                            ifTrue:[ (Array with:nodeValue) ]    
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   144
                            ifFalse:[ #() ].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   145
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   146
                left, middle, right
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   147
        ].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   148
    range := [:tree :min :max |
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   149
                rangeNode value:tree rootNode value:min value:max
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   150
        ].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   151
    range value:t value:30 value:60.                
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   152
                                                                [exEnd]
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   153
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   154
"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   155
! !
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   156
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   157
!BinaryTree class methodsFor:'initialization'!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   158
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   159
initialize
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   160
    "setup the default sortBlock.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   161
     Use #<, since this is the base method in Magnitude."
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   162
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   163
    "/ only do this once at early startup
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   164
    DefaultSortBlock isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   165
        DefaultSortBlock := [:a :b | a < b]
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   166
    ]
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   167
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   168
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   169
     BinaryTree initialize
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   170
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   171
! !
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   172
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   173
!BinaryTree class methodsFor:'instance creation'!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   174
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   175
new
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   176
    "return a new instance using the default sortOrder (which is a < b)"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   177
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   178
    ^ self basicNew sortBlock:DefaultSortBlock
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   179
!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   180
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   181
new:n
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   182
    "return a new instance using the default sortOrder (which is a < b)"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   183
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   184
    ^ self new
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   185
!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   186
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   187
sortBlock:aTwoArgBlock
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   188
    "return a new instance using the given sortBlock (which returns true if a < b)"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   189
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   190
    ^ self basicNew sortBlock:aTwoArgBlock
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   191
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   192
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   193
     |tree|
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   194
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   195
     tree := self sortBlock:[:a :b | a asLowercase < b asLowercase].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   196
     tree add:'hello'.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   197
     tree add:'aaaa'.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   198
     tree add:'AAAb'.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   199
     tree add:'aaaC'.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   200
     tree add:'world'.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   201
     tree asOrderedCollection
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   202
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   203
! !
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   204
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   205
!BinaryTree methodsFor:'accessing'!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   206
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   207
rootNode
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   208
    "return the rootNode of the tree"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   209
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   210
    ^ treeRoot
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   211
!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   212
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   213
sortBlock:something
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   214
    "set the sort block.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   215
     This is allowed only before any elements are stored in the tree"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   216
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   217
    self assert:treeRoot isNil message:'changing sortBlock in BinaryTree'.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   218
    sortBlock := something.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   219
! !
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   220
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   221
!BinaryTree methodsFor:'adding & removing'!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   222
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   223
add:anObject
2934
773f2ab36f52 comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2785
diff changeset
   224
    "add anObject to the collection. The object is inserted as defined by the sortBlock.
773f2ab36f52 comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2785
diff changeset
   225
     Returns anObject"
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   226
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   227
    treeRoot isNil ifTrue:[
2785
42c2ba93b504 changed: #add:
Claus Gittinger <cg@exept.de>
parents: 2777
diff changeset
   228
        treeRoot := self rootTreeNodeClass data:anObject.
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   229
    ] ifFalse:[
2785
42c2ba93b504 changed: #add:
Claus Gittinger <cg@exept.de>
parents: 2777
diff changeset
   230
        treeRoot insertNode:(self treeNodeClass data:anObject) sortBlock:sortBlock
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   231
    ].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   232
    ^ anObject "sigh - collection protocol"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   233
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   234
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   235
     BinaryTree withAll:#(16 3 1 0 4 7 9)
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   236
     BinaryTree new add:1; add:2; yourself
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   237
     BinaryTree with:1 with:2 with:3
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   238
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   239
2785
42c2ba93b504 changed: #add:
Claus Gittinger <cg@exept.de>
parents: 2777
diff changeset
   240
    "Modified: / 05-08-2012 / 12:34:42 / cg"
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   241
!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   242
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   243
includes:anElement
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   244
    "return true, if the argument, anObject is contained in the collection.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   245
     Uses #= when comparing; i.e. the search is for an equal object."
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   246
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   247
    treeRoot isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   248
        ^ false.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   249
    ].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   250
    ^ treeRoot includesValue:anElement sortBlock:sortBlock.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   251
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   252
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   253
     BinaryTree new 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   254
        addAll:#( 2 1 4.0 3 6 5 7); 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   255
        includes:4           
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   256
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   257
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   258
     BinaryTree new 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   259
        addAll:#( 2 1 4.0 3 6 5 7); 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   260
        includes:4.0           
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   261
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   262
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   263
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   264
     BinaryTree new 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   265
        addAll:#(2 1 4 3 6 5 7); 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   266
        includesIdentical:4           
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   267
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   268
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   269
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   270
     BinaryTree new 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   271
        addAll:#( 2 1 4.0 3 6 5 7); 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   272
        includesIdentical:4           
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   273
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   274
!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   275
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   276
includesIdentical:anElement
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   277
    "return true, if the argument, anObject is contained in the collection.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   278
     Uses #== (instead of #=) when comparing; 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   279
     i.e. the search is for the object itself, not some object being just equal."
2770
24caf488ddc1 tree node class is private
Claus Gittinger <cg@exept.de>
parents: 2763
diff changeset
   280
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   281
    treeRoot isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   282
        ^ false.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   283
    ].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   284
    ^ treeRoot includesIdenticalValue:anElement sortBlock:sortBlock.
2770
24caf488ddc1 tree node class is private
Claus Gittinger <cg@exept.de>
parents: 2763
diff changeset
   285
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   286
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   287
     BinaryTree new 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   288
        addAll:#(4 2 1 4.0 3 6 5 7); 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   289
        includesIdentical:4           
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   290
    "
2770
24caf488ddc1 tree node class is private
Claus Gittinger <cg@exept.de>
parents: 2763
diff changeset
   291
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   292
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   293
     BinaryTree new 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   294
        addAll:#( 2 1 4.0 3 6 5 7); 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   295
        includesIdentical:4           
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   296
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   297
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   298
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   299
     BinaryTree new 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   300
        addAll:#(4 2 1 3 6 5 7); 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   301
        includesIdentical:8
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   302
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   303
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   304
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   305
     BinaryTree new 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   306
        addAll:#( 2 1 4.0 3 6 5 7); 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   307
        includes:4           
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   308
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   309
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   310
     BinaryTree new 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   311
        addAll:#( 2 1 4.0 3 6 5 7); 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   312
        includes:4.0           
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   313
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   314
!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   315
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   316
remove:oldObject ifAbsent:exceptionValue
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   317
    |newRoot|
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   318
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   319
    treeRoot isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   320
        ^ exceptionValue value.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   321
    ].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   322
    newRoot := treeRoot removeValue:oldObject using:#= sortBlock:sortBlock.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   323
    newRoot isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   324
        treeRoot data = oldObject ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   325
            ^ exceptionValue value.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   326
        ].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   327
    ].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   328
    treeRoot := newRoot.    
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   329
    ^ oldObject "sigh - collection protocol"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   330
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   331
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   332
     BinaryTree new 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   333
        addAll:#(4 2 1 3 6 5 7); 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   334
        removeIdentical:4;
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   335
        yourself   
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   336
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   337
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   338
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   339
     BinaryTree new 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   340
        addAll:#(4 2 1 3 6 5 7); 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   341
        removeIdentical:7;
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   342
        yourself      
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   343
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   344
!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   345
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   346
removeIdentical:oldObject ifAbsent:exceptionValue
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   347
    |newRoot|
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   348
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   349
    treeRoot isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   350
        ^ exceptionValue value.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   351
    ].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   352
    newRoot := treeRoot removeValue:oldObject using:#== sortBlock:sortBlock.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   353
    newRoot isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   354
        treeRoot data == oldObject ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   355
            ^ exceptionValue value.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   356
        ].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   357
    ].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   358
    treeRoot := newRoot.    
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   359
    ^ oldObject "sigh - collection protocol"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   360
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   361
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   362
     BinaryTree new 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   363
        addAll:#(4 2 1 3 6 5 7); 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   364
        removeIdentical:4;
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   365
        yourself   
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   366
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   367
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   368
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   369
     BinaryTree new 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   370
        addAll:#(4 2 1 3 6 5 7); 
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   371
        removeIdentical:7;
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   372
        yourself      
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   373
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   374
! !
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   375
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   376
!BinaryTree methodsFor:'enumerating'!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   377
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   378
do:aBlock
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   379
    "enumerate the tree in order"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   380
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   381
    treeRoot notNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   382
        treeRoot inOrderDo:[:eachNode | aBlock value:(eachNode data)].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   383
    ].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   384
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   385
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   386
     |coll|
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   387
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   388
     coll:= OrderedCollection new.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   389
     (BinaryTree withAll:#(5 4 3 2 1 6 7 8 9 0)) do:[:each| coll add:each].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   390
     coll
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   391
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   392
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   393
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   394
     |coll|
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   395
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   396
     coll:= OrderedCollection new.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   397
     (BinaryTree withAll:#(5 4 3 2 1 6 7 8 9 0)) preOrderDo:[:each| coll add:each].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   398
     coll
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   399
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   400
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   401
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   402
     |coll|
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   403
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   404
     coll:= OrderedCollection new.
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   405
     (BinaryTree withAll:#(5 4 3 2 1 6 7 8 9 0)) postOrderDo:[:each| coll add:each].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   406
     coll
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   407
    "
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   408
!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   409
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   410
postOrderDo:aBlock
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   411
    "enumerate in postOrder - Left, Right, Root"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   412
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   413
    treeRoot notNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   414
        treeRoot postOrderDo:[:eachNode | aBlock value:(eachNode data)].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   415
    ].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   416
!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   417
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   418
preOrderDo:aBlock
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   419
    "enumerate in preOrder - Root, Left, Right"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   420
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   421
    treeRoot notNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   422
        treeRoot preOrderDo:[:eachNode | aBlock value:(eachNode data)].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   423
    ].
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   424
! !
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   425
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   426
!BinaryTree methodsFor:'queries'!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   427
3015
b85fdeed7329 added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
   428
isFixedSize
b85fdeed7329 added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
   429
    "return true if the receiver cannot grow"
b85fdeed7329 added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
   430
b85fdeed7329 added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
   431
    ^ false
b85fdeed7329 added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
   432
!
b85fdeed7329 added isFixedSize query
Claus Gittinger <cg@exept.de>
parents: 2934
diff changeset
   433
2785
42c2ba93b504 changed: #add:
Claus Gittinger <cg@exept.de>
parents: 2777
diff changeset
   434
rootTreeNodeClass
42c2ba93b504 changed: #add:
Claus Gittinger <cg@exept.de>
parents: 2777
diff changeset
   435
    ^ self treeNodeClass
42c2ba93b504 changed: #add:
Claus Gittinger <cg@exept.de>
parents: 2777
diff changeset
   436
42c2ba93b504 changed: #add:
Claus Gittinger <cg@exept.de>
parents: 2777
diff changeset
   437
    "Created: / 05-08-2012 / 12:30:26 / cg"
42c2ba93b504 changed: #add:
Claus Gittinger <cg@exept.de>
parents: 2777
diff changeset
   438
!
42c2ba93b504 changed: #add:
Claus Gittinger <cg@exept.de>
parents: 2777
diff changeset
   439
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   440
size
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   441
    "return the number of tree elements"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   442
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   443
    ^ treeRoot size
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   444
!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   445
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   446
treeNodeClass
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   447
    ^ BinaryTreeNode
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   448
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   449
    "Created: / 05-08-2012 / 11:36:26 / cg"
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   450
! !
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   451
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   452
!BinaryTree class methodsFor:'documentation'!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   453
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   454
version
3666
0425141734d6 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3015
diff changeset
   455
    ^ '$Header$'
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   456
!
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   457
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   458
version_CVS
3666
0425141734d6 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 3015
diff changeset
   459
    ^ '$Header$'
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   460
! !
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   461
2934
773f2ab36f52 comment/format in: #add:
Claus Gittinger <cg@exept.de>
parents: 2785
diff changeset
   462
2777
Claus Gittinger <cg@exept.de>
parents: 2776
diff changeset
   463
BinaryTree initialize!