Anonymous user
Order two numerical lists: Difference between revisions
m
→{{header|REXX}}: added/changed comments and whitespace, used a template for the output section.
(added Ol) |
m (→{{header|REXX}}: added/changed comments and whitespace, used a template for the output section.) |
||
Line 1,383:
=={{header|REXX}}==
This
<br>This example will also work with non-numeric strings.▼
<lang rexx>/*REXX pgm determines if a list < previous list, & returns true | false*/▼
@.4 = 1 2 3 4 5 /* [↓] compare list to previous.*/▼
do j=2 while @.j\==''; p=j-1 /*P is the previous.*/▼
answer=FNorder(@.p, @.j) /*obtain the answer.*/▼
if answer=='true' then is= ' < ' /*convert from true */▼
else is= ' ≥ ' /*convert from false*/▼
say right('['@.p"]", 40) is '['@.j"]"; say▼
end /*i*/ /* [↑] display (+ a blank line)*/▼
exit /*stick a fork in it, we're done.*/▼
FNorder: procedure; parse arg x,y; wx=words(x); wy=words(y)▼
do k=1 for min(wx,wy)▼
▲<lang rexx>/*REXX
a=word(x,k); b=word(y,k)▼
@.=; @.1 = 1 2 1 5
@.2 = 1 2 1 5 2
@.3 = 1 2 3 4
if wx<wy then return 'true'▼
return 'false'</lang>▼
{{out}}▼
else is= " ≥ " /* " " " " " " " */
say
end /*i*/
▲exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
wx= words(x); wy= words(y)
b= word(y, k) /* " " " " Y.*/
if a<b then return 'true'
else if a>b then return 'false'
▲ if wx<wy then return 'true'
▲ return 'false'</lang>
▲{{out|output|:}}
<pre>
[1 2 1 5 2] < [1 2 1 5 2 2]
|