bintreeSearch - % branch as the root. % if element is...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function [out] = bintreeSearch(tree, element) % % out is 1 if element value is contained in tree, 0 otherwise % % base case is if root is equal to value if isempty(tree) %obviously element is not in tree out = 0; elseif tree.val == element % then obviously this is true out = 1; else % if element is less than tree.val, then make recursive call with left
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % branch as the root. % if element is greater than tree.val, then make recursive call with % right branch as root. if element < tree.val out = bintreeSearch(tree.left, element); elseif element > tree.val out = bintreeSearch(tree.right, element); end end % end if tree.val end % end bintreeSearch.m...
View Full Document

Ask a homework question - tutors are online