@@ -158,31 +158,31 @@ outlined above. We use these predecessor/successor attributes to great effect
158
158
in this new algorithm for both forward and backward traversals:
159
159
160
160
``` swift
161
- func traverseInOrderForward (visit : T -> Void ) {
162
- var n: ThreadedBinaryTree
163
- n = minimum ()
164
- while true {
165
- visit (n.value )
166
- if let successor = n.successor () {
167
- n = successor
168
- } else {
169
- break
161
+ public func traverseInOrderForward (_ visit : (T) -> Void ) {
162
+ var n: ThreadedBinaryTree
163
+ n = minimum ()
164
+ while true {
165
+ visit (n.value )
166
+ if let successor = n.successor () {
167
+ n = successor
168
+ } else {
169
+ break
170
+ }
171
+ }
170
172
}
171
- }
172
- }
173
173
174
- func traverseInOrderBackward (visit : T -> Void ) {
175
- var n: ThreadedBinaryTree
176
- n = maximum ()
177
- while true {
178
- visit (n.value )
179
- if let predecessor = n.predecessor () {
180
- n = predecessor
181
- } else {
182
- break
174
+ public func traverseInOrderBackward (_ visit : (T) -> Void ) {
175
+ var n: ThreadedBinaryTree
176
+ n = maximum ()
177
+ while true {
178
+ visit (n.value )
179
+ if let predecessor = n.predecessor () {
180
+ n = predecessor
181
+ } else {
182
+ break
183
+ }
184
+ }
183
185
}
184
- }
185
- }
186
186
```
187
187
Again, this a method of ` ThreadedBinaryTree ` , so we'd call it via
188
188
` node.traverseInorderForward(visitFunction) ` . Note that we are able to specify
@@ -221,7 +221,7 @@ continuously manage the `leftThread` and `rightThread` variables. Rather than
221
221
walking through some boring code, it is best to explain this with an example
222
222
(although you can read through [ the implementation] ( ThreadedBinaryTree.swift )
223
223
if you want to know the finer details). Please note that this requires
224
- knowledge of binary search trees, so make sure you have
224
+ knowledge of binary search trees, so make sure you have
225
225
[ read this first] (../Binary Search Tree/).
226
226
227
227
> Note: we do allow duplicate nodes in this implementation of a threaded binary
@@ -342,11 +342,12 @@ Many of these methods are inherent to binary search trees as well, so you can
342
342
find [ further documentation here] (../Binary Search Tree/).
343
343
344
344
345
- ## See also
345
+ ## See also
346
346
347
347
[ Threaded Binary Tree on Wikipedia] ( https://en.wikipedia.org/wiki/Threaded_binary_tree )
348
348
349
349
* Written for the Swift Algorithm Club by
350
350
[ Jayson Tung] ( https://github.com/JFTung ) *
351
+ * Migrated to Swift 3 by Jaap Wijnen*
351
352
352
353
* Images made using www.draw.io *
0 commit comments