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