home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 13 / CD_ASCQ_13_0494.iso / maj / 419 / binseekl.bas < prev    next >
BASIC Source File  |  1994-03-13  |  1KB  |  39 lines

  1. '   +----------------------------------------------------------------------+
  2. '   |                                                                      |
  3. '   |        PBClone  Copyright (c) 1990-1994  Thomas G. Hanlin III        |
  4. '   |                                                                      |
  5. '   +----------------------------------------------------------------------+
  6.  
  7. SUB BinSeekL (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.