searchBinary

searchBinary - % returns true. Otherwise, the function...

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

View Full Document Right Arrow Icon
% 10/22/2009 5:34 AM % Function Name: searchBinary % Inputs: 1. struct - a structure with three fields, 'data', 'left', and % 'right'. The structure represents the root of a binary tree, % where the 'left' and 'right' fields contain the leaves. % 2. double scalar - the value that the function is searching for % % Outputs: 1. boolean scalar - a true or false on whether the inputted % number existed in the Binary Tree. % % Function Description: % The function takes in a structure representing the root node of a % binary tree and a value that is being searched for. If the a node % exists in the binary tree containing that value, then the function
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % returns true. Otherwise, the function returns false. % function check = searchBinary(struct, num) if struct.data==num % if found, true check = true; elseif isempty(struct.left) && isempty(struct.right) % if no more and not found, false check = false; elseif isempty(struct.left) % if no more left, search only right check = searchBinary(struct.right, num); elseif isempty(struct.right) % if no more right, search only left check = searchBinary(struct.left, num); else % if both left and right but not found, look in both left and right check = searchBinary(struct.left, num) || searchBinary(struct.right, num); end end...
View Full Document

Ask a homework question - tutors are online