summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo <mokha@cisco.com>2017-08-09 15:30:18 -0600
committermo <mokha@cisco.com>2017-08-09 15:30:18 -0600
commit7b87acbf26797cf8383095d9d508d0684880225e (patch)
tree4a83b4a33fc70be8a3aeed8e3d56a15dee62c9a5
parent2528c1dcc3beef34f961427701e5a32e28822e9e (diff)
remove usage of Tree class and use hash.
-rw-r--r--spec/binary_trees/restore_binary_tree_spec.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/spec/binary_trees/restore_binary_tree_spec.rb b/spec/binary_trees/restore_binary_tree_spec.rb
index 2f42ca6..f8d457c 100644
--- a/spec/binary_trees/restore_binary_tree_spec.rb
+++ b/spec/binary_trees/restore_binary_tree_spec.rb
@@ -92,19 +92,19 @@ describe "#restore_binary_tree" do
return nil if start_index > end_index
value = preorder[$preorder_index]
- node = Tree.new(value)
+ node = { value: value, left: nil, right: nil }
$preorder_index += 1
return node if start_index == end_index
index = search(inorder[start_index..end_index], value) + start_index
- node.left = build_tree(inorder, preorder, start_index, index - 1)
- node.right = build_tree(inorder, preorder, index + 1, end_index)
+ node[:left] = build_tree(inorder, preorder, start_index, index - 1)
+ node[:right] = build_tree(inorder, preorder, index + 1, end_index)
node
end
def restore_binary_tree(inorder, preorder)
- build_tree(inorder, preorder, 0, inorder.size - 1).to_h
+ build_tree(inorder, preorder, 0, inorder.size - 1)
end
null = nil