diff options
| author | mo <mokha@cisco.com> | 2017-08-09 15:41:56 -0600 |
|---|---|---|
| committer | mo <mokha@cisco.com> | 2017-08-09 15:41:56 -0600 |
| commit | 10b104db8154f3ce635d38c1c1b606591a7b718c (patch) | |
| tree | 9a1e9f3e0f41682258c5bd8eac971073514d76bc | |
| parent | 1a28d18e193a30e1d16b06837f8182966211cabd (diff) | |
remove search method.
| -rw-r--r-- | spec/binary_trees/restore_binary_tree_spec.rb | 9 |
1 files changed, 1 insertions, 8 deletions
diff --git a/spec/binary_trees/restore_binary_tree_spec.rb b/spec/binary_trees/restore_binary_tree_spec.rb index 29f241a..f13c7f1 100644 --- a/spec/binary_trees/restore_binary_tree_spec.rb +++ b/spec/binary_trees/restore_binary_tree_spec.rb @@ -84,10 +84,6 @@ DOC describe "#restore_binary_tree" do $preorder_index = 0 - def search(items, target) - items.find_index { |x| x == target } - end - def restore_binary_tree(inorder, preorder, start_index = 0, end_index = inorder.size - 1) return nil if start_index > end_index @@ -97,10 +93,7 @@ describe "#restore_binary_tree" do return node if start_index == end_index - index = search(inorder[start_index..end_index], value) + start_index - - items.find_index { |x| x == target } - + index = inorder[start_index..end_index].find_index { |x| x == value } + start_index node[:left] = restore_binary_tree(inorder, preorder, start_index, index - 1) node[:right] = restore_binary_tree(inorder, preorder, index + 1, end_index) node |
