home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP19.EXE / CHP1903.PRG < prev    next >
Encoding:
Text File  |  1991-04-30  |  668 b   |  27 lines

  1. /*
  2.    Listing 19.3  Bsearch
  3.    Author: Joe Booth
  4.    Excerpted from "Clipper 5: A Developer's Guide"
  5.    Copyright (c) 1991 M&T Books
  6.                       501 Galveston Drive
  7.                       Redwood City, CA 94063-4728
  8.                       (415) 366-3600
  9. */
  10.  
  11. function Bsearch(nfield, the_key)
  12. LOCAL retval := .F., bottom := Lastrec(), top := 1, mid := 0
  13. while top <= bottom .and. ! retval
  14.    mid := int( (top + bottom) /2 )
  15.    goto mid
  16.    if fieldget(nfield) == the_key
  17.       retval :=.T.
  18.    elseif fieldget(nfield) < the_key
  19.       bottom := mid + 1
  20.    else
  21.       top := mid - 1
  22.    endif
  23. enddo
  24. return retval
  25.  
  26. // end of file CHP1903.PRG
  27.