Hi, since there is no way i can learn someone elses algorithm i thought i will try make my own one but It's a little different to whats in textbooks. Im just wondering if this is "acceptable" as it works when testing it.
Thank You.
PHP:
Begin BinarySearch ( MyArray, Value )
Set lowValue to 1st index of MyArray;
Set topValue to last index of MyArray;
WHILE ( lowValue < = topValue ) DO
midValue = ( lowValue + topValue ) / 2;
Select case MyArray ( midValue )
case: = Value
return midValue;
case: < Value
Set lowValue to midValue + 1;
case: > Value
Set topValue to midValue - 1;
end Select;
END WHILE
return - 1;
end BinarySearch ( )
Last edited: