Sort three variables: Difference between revisions

Content deleted Content added
No edit summary
m →‎{{header|REXX}}: undid someone's older change, added/changed whitespace.
Line 2,055: Line 2,055:
say '───── original value of Y: ' y
say '───── original value of Y: ' y
say '───── original value of Z: ' z
say '───── original value of Z: ' z
if x>y then do; _=x; x=y; y=_; end /*swap the values of X and Y. */ /* ◄─── sorting.*/
if x>y then do; _= x; x= y; y= _; end /*swap the values of X and Y. */ /* ◄─── sorting.*/
if y>z then do; _=y; y=z; z=_; end /* " " " " Y " Z. */ /* ◄─── sorting.*/
if y>z then do; _= y; y= z; z= _; end /* " " " " Y " Z. */ /* ◄─── sorting.*/
if x>y then do; _=x; x=y; y=_; end /* " " " " X " Y. */ /* ◄─── sorting */
if x>y then do; _= x; x= y; y= _; end /* " " " " X " Y. */ /* ◄─── sorting */
say /*stick a fork in it, we're all done. */
say /*stick a fork in it, we're all done. */
say '═════ sorted value of X: ' x
say '═════ sorted value of X: ' x
Line 2,063: Line 2,063:
say '═════ sorted value of Z: ' z</lang>
say '═════ sorted value of Z: ' z</lang>
{{out|output|text=when using the default inputs:}}
{{out|output|text=when using the default inputs:}}
<pre>
<pre>───── original value of X: lions, tigers, and
───── original value of X: lions, tigers, and
───── original value of Y: bears, oh my!
───── original value of Y: bears, oh my!
───── original value of Z: (from "The Wizard of Oz")
───── original value of Z: (from "The Wizard of Oz")
Line 2,069: Line 2,070:
═════ sorted value of X: (from "The Wizard of Oz")
═════ sorted value of X: (from "The Wizard of Oz")
═════ sorted value of Y: bears, oh my!
═════ sorted value of Y: bears, oh my!
═════ sorted value of Z: lions, tigers, and</pre>
═════ sorted value of Z: lions, tigers, and
</pre>


===numeric only===
===numeric only===
Line 2,081: Line 2,083:
if y=='' | y=="," then y= -12 /* " " " " " " */
if y=='' | y=="," then y= -12 /* " " " " " " */
if z=='' | z=="," then z= 0 /* " " " " " " */
if z=='' | z=="," then z= 0 /* " " " " " " */
w=max( length(x), length(y), length(z) ) + 5 /*find max width of the values, plus 5.*/
w= max( length(x), length(y), length(z) ) + 5 /*find max width of the values, plus 5.*/
say '───── original values of X, Y, and Z: ' right(x, w) right(y, w) right(z, w)
say '───── original values of X, Y, and Z: ' right(x, w) right(y, w) right(z, w)
low = x /*assign a temporary variable. */ /* ◄─── sorting.*/
low = x /*assign a temporary variable. */
mid = y /* " " " " */ /* ◄─── sorting.*/
mid = y /* " " " " */
high= z /* " " " " */ /* ◄─── sorting.*/
high= z /* " " " " */
x=min(low, mid, high) /*determine the lowest value of X,Y,Z. */ /* ◄─── sorting.*/
x= min(low, mid, high) /*determine the lowest value of X,Y,Z. */ /* ◄─── sorting.*/
z=max(low, mid, high) /* " " highest " " " " " */ /* ◄─── sorting.*/
z= max(low, mid, high) /* " " highest " " " " " */ /* ◄─── sorting.*/
y= low + mid + high - x - z /* " " middle " " " " " */ /* ◄─── sorting.*/
y= low + mid + high - x - z /* " " middle " " " " " */ /* ◄─── sorting.*/
/*stick a fork in it, we're all done. */
/*stick a fork in it, we're all done. */
say '═════ sorted values of X, Y, and Z: ' right(x, w) right(y, w) right(z, w)</lang>
say '═════ sorted values of X, Y, and Z: ' right(x, w) right(y, w) right(z, w)</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
<pre>───── original values of X, Y, and Z: 77444 -12 0
═════ sorted values of X, Y, and Z: -12 0 77444</pre>
───── original values of X, Y, and Z: 77444 -12 0
═════ sorted values of X, Y, and Z: -12 0 77444
</pre>


=={{header|Ring}}==
=={{header|Ring}}==