Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
19
Task/Binary-search/ZX-Spectrum-Basic/binary-search.basic
Normal file
19
Task/Binary-search/ZX-Spectrum-Basic/binary-search.basic
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
10 DATA 2,3,5,6,8,10,11,15,19,20
|
||||
20 DIM t(10)
|
||||
30 FOR i=1 TO 10
|
||||
40 READ t(i)
|
||||
50 NEXT i
|
||||
60 LET value=4: GO SUB 100
|
||||
70 LET value=8: GO SUB 100
|
||||
80 LET value=20: GO SUB 100
|
||||
90 STOP
|
||||
100 REM Binary search
|
||||
110 LET lo=1: LET hi=10
|
||||
120 IF lo>hi THEN LET idx=0: GO TO 170
|
||||
130 LET middle=INT ((hi+lo)/2)
|
||||
140 IF value<t(middle) THEN LET hi=middle-1: GO TO 120
|
||||
150 IF value>t(middle) THEN LET lo=middle+1: GO TO 120
|
||||
160 LET idx=middle
|
||||
170 PRINT "Value ";value;
|
||||
180 IF idx=0 THEN PRINT " not found": RETURN
|
||||
190 PRINT " found at index ";idx: RETURN
|
||||
Loading…
Add table
Add a link
Reference in a new issue