Created
December 28, 2009 17:19
-
-
Save kidd/264785 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun bin-search (obj vect) | |
| (bin-search-rec obj vect 0 (1- (length vect)))) | |
| (defun bin-search-rec (obj vec start end) | |
| (let* ((range (- end start)) | |
| (mid (+ start (round (/ range 2))))) | |
| (cond ((eq (aref vec mid) obj) (format t "l'hem trobat a la posicio blabla ~A" mid)) | |
| ((zerop range) nil) | |
| ((< (aref vec mid) obj) (bin-search-rec obj vec (1+ mid) end)) | |
| ((> (aref vec mid) obj) (bin-search-rec obj vec start (1- mid)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment