Binary search: Difference between revisions
Content deleted Content added
No edit summary |
|||
Line 662: | Line 662: | ||
190 PRINT "The value";N;"was not found." |
190 PRINT "The value";N;"was not found." |
||
200 END IF |
200 END IF |
||
210 DEF |
210 DEF FILL(REF T) |
||
220 LET |
220 LET T(1)=RND(3):PRINT T(1); |
||
230 |
230 FOR I=LBOUND(T)+1 TO UBOUND(T) |
||
240 LET T(I)=T(I-1)+RND(3)+1 |
|||
240 DO |
|||
250 |
250 PRINT T(I); |
||
260 NEXT |
|||
⚫ | |||
⚫ | |||
270 IF T(K)>N THEN LET UP=K-1 |
|||
280 |
280 DEF SEARCH(REF T,N) |
||
290 |
290 LET SEARCH=0:LET BO=LBOUND(T):LET UP=UBOUND(T) |
||
300 |
300 DO |
||
310 LET K=INT((BO+UP)/2) |
|||
310 DEF FILL(REF T) |
|||
320 |
320 IF T(K)<N THEN LET BO=K+1 |
||
⚫ | |||
330 FOR I=LBOUND(T)+1 TO UBOUND(T) |
|||
340 |
340 LOOP WHILE BO<=UP AND T(K)<>N |
||
350 |
350 IF BO<=UP THEN LET SEARCH=K |
||
360 |
360 END DEF</lang> |
||
⚫ | |||
=={{header|Batch File}}== |
=={{header|Batch File}}== |