Knapsack problem/Continuous: Difference between revisions

m
→‎version 1: changed indentation and whitespace.
m (→‎version 1: added/changed comments and whitespace.)
m (→‎version 1: changed indentation and whitespace.)
Line 2,830:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
sortD: do s=2 to #; a=n.s; !=w.s; u=v.s /* [↓] this is a descending sort. */
do k=s-1 by -1 to 1 while v.k/w.k<u/!; ?=k+1; n.?=n.k; w.?=w.k; v.?=v.k; end
?=k+1; n.?=a; w.?=!; v.?=u
end /*s*/; return /* ↑↑↑ algorithm is OK for small arrays*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
hdr: say; say; say center(arg(1),50,'─'); say; call title; call sep; return