This sounds like "homework".
A binary-search requires an "ordered" table of values.
Sort your values into the proper order.
LET TOP=1; * Point to first element in the table.
LET BOT=1000; * Point to the *LAST* item in the table.
LOOPHERE:
LET BINARY = 2;
LET MIDDLE=FLOOR((TOP+BOT)/BINARY);
IF VALUE(MIDDLE) = KEY THEN STOP;
IF KEY < VALUE(MIDDLE)
THEN TOP = MIDDLE;
ELSE BOTTOM = MIDDLE;
IF TOP = BOTTOM THEN STOP;
GOTO LOOPHERE;
END;
546 views
Usually answered in minutes!
×