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 R<tt>EXX</tt>REXX example uses the same lists as &nbsp; &nbsp; <tt> ''BBC BASIC''. </tt>
<br>This example will also work with non-numeric strings.
<lang rexx>/*REXX pgm determines if a list < previous list, & returns true | false*/
@. =
@.1 = 1 2 1 5 2
@.2 = 1 2 1 5 2 2
@.3 = 1 2 3 4 5
@.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 subroutine──────────────────*/
FNorder: procedure; parse arg x,y; wx=words(x); wy=words(y)
 
<br>This example will also work with non-numeric strings.
do k=1 for min(wx,wy)
<lang rexx>/*REXX pgmprogram determines if a list < previous list, & and returns true | or false. */
a=word(x,k); b=word(y,k)
@.=; @.1 = 1 2 1 5 if a<b then return 'true'2
@.2 = 1 2 1 5 2 else if a>b then return 'false'2
@.3 = 1 2 3 4 end /*k*/5
@.4 = 1 2 3 4 do k=1 for min(wx,wy)5
if wx<wy then return 'true'
@.4 = 1 2 3 4 5 /* [↓] compare a list to previous. list*/
return 'false'</lang>
do j=2 while @.j\==''; p= j -1 1 /*P: is thepoints to previous value in list.*/
{{out}}
answer= FNorder(@.p, @.j) /*obtain the answer.*/
 
if answer=='true' then is= '" < '" /*convertuse froma truemore familiar glyph for display*/
else is= " ≥ " /* " " " " " " " */
say
say right('['@.p"]", 40) is '['@.j"]"; say
end /*i*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
FNorder: procedure; parse arg x,y; wx=words(x); wy=words(y)
wx= words(x); wy= words(y)
end /*i*/ /* [↑] display (+ a blank line do k=1 for min(wx, wy)*/
a= word(x, k); b=word(y,k) /*get a value from X.*/
b= word(y, k) /* " " " " Y.*/
if a<b then return 'true'
else if a>b then return 'false'
else is= ' ' end /*convert from false/*k*/
if wx<wy then return 'true'
return 'false'</lang>
{{out|output|:}}
<pre>
[1 2 1 5 2] < [1 2 1 5 2 2]