Binary search: Difference between revisions

m (→‎{{header|Ol}}: Tweak irregular header markup)
Line 5,499:
Written from pseudocode for rightmost insertion point, iterative.
 
<lang Quackery> [ stack ] is value.bs ( --> n )
[ stack ] is nest.bs ( --> n )
[ stack ] dup dip [ not + ] ] is binarysearchtest.bs ( [ n --> n b )
 
[ value]'[ test.bs put
dup nestvalue.bs put
sizenest.bs 1 - 0put
swap
[ 2dup < if done
2dup + 1 >>
nest.bs share over peek
value.bs share > iffswap
test.bs share do iff
[ 1 - unrot nip ]
again
[ 1+ nip ] again ]
drop
nest.bs take over peek
value.bs take =2dup swap
test.bs share do
dup dip [ not + ] ] is binarysearch ( [ n --> n b )
dip [ test.bs take do ]
or not
dup dip [ not + ] ] is bsearchwith ( n n [ n --> n b )
 
[ dup echo
over size 1 - 0 swap 2swap
binarysearch iff
bsearchwith < iff
[ say " was identified as item " ]
else
[ say " could go into position " ]
echo
say "." cr ] is task ( [ n --> n )</lang>
 
{{out}}
1,462

edits