summaryrefslogtreecommitdiff
path: root/lib/data_structures/binary_tree.rb
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2013-07-13 10:46:54 -0600
committermo khan <mo@mokhan.ca>2013-07-13 10:46:54 -0600
commit84b475c43132d50d2ec00390e65b6ed3d5d64a56 (patch)
tree444f6ebada694a124fd74728c7b908d7b37f27df /lib/data_structures/binary_tree.rb
parent0225329a4502070d8af17df6401af691643f7a45 (diff)
extract block visitor to utility
Diffstat (limited to 'lib/data_structures/binary_tree.rb')
-rw-r--r--lib/data_structures/binary_tree.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/data_structures/binary_tree.rb b/lib/data_structures/binary_tree.rb
index 15b72b7..b658515 100644
--- a/lib/data_structures/binary_tree.rb
+++ b/lib/data_structures/binary_tree.rb
@@ -1,3 +1,5 @@
+require_relative "../utility/block_visitor"
+
class BinaryTree
def push(item)
if @root
@@ -17,6 +19,10 @@ class BinaryTree
@root.accept(visitor, traversal) if @root
end
+ def each(&block)
+ accept(BlockVisitor.new(&block))
+ end
+
class BinaryTreeNode
attr_reader :left, :right, :data