home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / QBAS / PBC22B.ZIP / PBC$BAS.ZIP / BINSEEKS.BAS < prev    next >
BASIC Source File  |  1993-01-01  |  1KB  |  39 lines

  1. '   +----------------------------------------------------------------------+
  2. '   |                                                                      |
  3. '   |        PBClone  Copyright (c) 1990-1993  Thomas G. Hanlin III        |
  4. '   |                                                                      |
  5. '   +----------------------------------------------------------------------+
  6.  
  7. SUB BinSeekS (Array!(), Elements%, Target!, Posn%)
  8.    IF Elements% = 0 THEN
  9.       Posn% = -1
  10.    ELSE
  11.       Top% = 1
  12.       Bottom% = Elements% + 1
  13.       OldPlace% = Bottom%
  14.       DO
  15.          Place% = (Top% + Bottom%) \ 2
  16.          IF Place% = OldPlace% THEN
  17.             NotThere% = -1
  18.          ELSEIF Array!(Place%) = Target! THEN
  19.             Found% = -1
  20.          ELSEIF Array!(Place%) > Target! THEN
  21.             Bottom% = Place%
  22.          ELSE
  23.             Top% = Place%
  24.          END IF
  25.          OldPlace% = Place%
  26.       LOOP UNTIL Found% OR NotThere%
  27.       IF NotThere% THEN
  28.          IF Elements% = UBOUND(Array!) THEN
  29.             Posn% = 0
  30.          ELSE
  31.             IF Target! > Array!(Place%) THEN Place% = Place% + 1
  32.             Posn% = -Place%
  33.          END IF
  34.       ELSE
  35.          Posn% = Place%
  36.       END IF
  37.    END IF
  38. END SUB
  39.