From 84b475c43132d50d2ec00390e65b6ed3d5d64a56 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 13 Jul 2013 10:46:54 -0600 Subject: extract block visitor to utility --- lib/data_structures/binary_tree.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/data_structures/binary_tree.rb') 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 -- cgit v1.2.3