Skip to content

Commit 75a94e3

Browse files
committed
Finish threaded bin. tree images
1 parent 7914569 commit 75a94e3

12 files changed

+84
-19
lines changed

Diff for: Threaded Binary Tree/Images/DelOne.png

-16.8 KB
Binary file not shown.

Diff for: Threaded Binary Tree/Images/DelThree.png

-11.3 KB
Binary file not shown.

Diff for: Threaded Binary Tree/Images/DelTwo.png

-13.3 KB
Binary file not shown.
File renamed without changes.
File renamed without changes.

Diff for: Threaded Binary Tree/Images/Insert3.png

19.9 KB
Loading

Diff for: Threaded Binary Tree/Images/Remove1.png

16.6 KB
Loading

Diff for: Threaded Binary Tree/Images/Remove2.png

13.8 KB
Loading

Diff for: Threaded Binary Tree/Images/Remove3.png

12.5 KB
Loading

Diff for: Threaded Binary Tree/Images/Remove4.png

11.7 KB
Loading

Diff for: Threaded Binary Tree/README.markdown

+53
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,26 @@ need to keep track of both. For example, in a double threaded tree, if a node
7373
has a right child but no left child, it will track its predecessor in place of
7474
its left child.
7575

76+
Here is a valid "full" threaded binary tree:
77+
78+
![Full](/Images/Full.png)
79+
80+
While the following threaded binary tree is not "full," it is still valid. The
81+
structure of the tree does not matter as long as it follows the definition of a
82+
binary search tree:
83+
84+
![Partial](/Images/Partial.png)
85+
86+
The solid lines denote the links between parents and children, while the dotted
87+
lines denote the "threads." The important thing to note here is how the
88+
children and thread edges interact with each other. Every node besides the
89+
root has one entering edge (from its parent), and two leaving edges: one to the
90+
left and one to the right. The left leaving edge goes to the node's left child
91+
if it exists, and to its in-order predecessor if it does not. The right
92+
leaving edge goes to the node's right child if it exists, and to its in-order
93+
successor if it does not. The exceptions are the left-most node and the
94+
right-most node, which do not have a predecessor or successor, respectively.
95+
7696

7797
## Representation
7898

@@ -175,6 +195,39 @@ to explain this with an example. Please note that this requires knowledge of
175195
binary search trees, so make sure you have
176196
[read this first](../Binary Search Tree/).
177197

198+
Base:
199+
200+
![Base](/Images/Base.png)
201+
202+
Insert1:
203+
204+
![Insert1](/Images/Insert1.png)
205+
206+
Insert2:
207+
208+
![Insert2](/Images/Insert2.png)
209+
210+
Insert3:
211+
212+
![Insert3](/Images/Insert3.png)
213+
214+
Remove1:
215+
216+
![Remove1](/Images/Remove1.png)
217+
218+
Remove2:
219+
220+
![Remove2](/Images/Remove2.png)
221+
222+
Remove3:
223+
224+
![Remove3](/Images/Remove3.png)
225+
226+
Remove4:
227+
228+
![Remove4](/Images/Remove4.png)
229+
230+
178231

179232
### Still under construction.
180233

Diff for: Threaded Binary Tree/ThreadedBinaryTree.swift

+31-19
Original file line numberDiff line numberDiff line change
@@ -485,20 +485,24 @@ extension ThreadedBinaryTree: CustomDebugStringConvertible {
485485
*/
486486

487487
// Simple little debug function to make testing output pretty
488-
private func check(tree: ThreadedBinaryTree<Int>) {
489-
print("\(tree.count) Total Nodes:");
490-
print(tree)
491-
print("Debug Info:")
492-
print(tree.debugDescription)
493-
print("In-Order Traversal:")
494-
let myArray = tree.toArray()
495-
for node in myArray {
496-
print(node)
497-
}
498-
if tree.isThreaded() {
499-
print("This threaded binary tree is VALID.")
488+
private func check(tree: ThreadedBinaryTree<Int>?) {
489+
if let tree = tree {
490+
print("\(tree.count) Total Nodes:");
491+
print(tree)
492+
print("Debug Info:")
493+
print(tree.debugDescription)
494+
print("In-Order Traversal:")
495+
let myArray = tree.toArray()
496+
for node in myArray {
497+
print(node)
498+
}
499+
if tree.isThreaded() {
500+
print("This threaded binary tree is VALID.")
501+
} else {
502+
print("This threaded binary tree is INVALID.")
503+
}
500504
} else {
501-
print("This threaded binary tree is INVALID.")
505+
print("This tree is nil.")
502506
}
503507
}
504508

@@ -530,20 +534,28 @@ print("\nInsert 4")
530534
tree.insert(4)
531535
check(tree)
532536

533-
print("\nRemove 13 (Not in the Tree)")
534-
tree.remove(13)
537+
print("\nInsert 15")
538+
tree.insert(15)
535539
check(tree)
536540

537-
print("\nRemove 5")
538-
tree.remove(5)
541+
print("\nRemove 13 (Not in the Tree)")
542+
tree.remove(13)
539543
check(tree)
540544

541545
print("\nRemove 7")
542546
tree.remove(7)
543547
check(tree)
544548

545-
print("\nRemove 10")
546-
tree.remove(10)
549+
print("\nRemove 5")
550+
tree.remove(5)
547551
check(tree)
548552

553+
print("\nRemove 9 (root)")
554+
let newRoot = tree.remove(9)
555+
check(newRoot)
556+
557+
print("\nRemove 12")
558+
newRoot?.remove(12)
559+
check(newRoot)
560+
549561
print("\n\nDone with Tests!\n")

0 commit comments

Comments
 (0)