Sort three variables: Difference between revisions

 
(6 intermediate revisions by 6 users not shown)
Line 298:
+0
+77444</pre>
 
=={{header|Amazing Hopper}}==
<syntaxhighlight lang="c">
 
#include <basico.h>
 
algoritmo
 
x = 77444, y = -12.5, z = 0
low=x, midd=y, high=z
imprimir("BEFORE:\nX = ",x, " Y = ",y, " Z = ",z,NL)
#basic{
x = min( min( low,midd),high)
z = max( max( low,midd),high)
y = low + midd + high - x - z
}
 
imprimir("\nAFTER:\nX = ",x, " Y = ",y, " Z = ",z,NL,NL)
 
x = "lions, tigers, and"
y = "bears, oh my!"
z = "(from the \"Wizard of OZ\")"
imprimir("BEFORE:\nX = ",x, "\nY = ",y, "\nZ = ",z,NL)
#(x > y), entonces { intercambiar( x,y) }
#(y > z), entonces {
intercambiar (y,z )
#(x > y), entonces { intercambiar( x,y ) }
}
 
imprimir("\nAFTER:\nX = ",x, "\nY = ",y, "\nZ = ",z,NL,NL)
 
p = {}
'"lions, tigers, and",77444,"bears, oh my!",-12.7,0,"(from the \"Wizard of OZ\")"'
enlistar en 'p'
 
fijar separador 'NL'
imprimir("BEFORE:\n",p,NL)
matriz.ordenar(p)
imprimir("\nAFTER:\n",p,NL)
 
 
terminar
</syntaxhighlight>
{{out}}
<pre>
$ hopper3 basica/sort3var.bas
BEFORE:
X = 77444 Y = -12.500000 Z = 0
 
AFTER:
X = -12.500000 Y = 0.000000 Z = 77444.000000
 
BEFORE:
X = lions, tigers, and
Y = bears, oh my!
Z = (from the "Wizard of OZ")
 
AFTER:
X = (from the "Wizard of OZ")
Y = bears, oh my!
Z = lions, tigers, and
 
BEFORE:
lions, tigers, and
77444
bears, oh my!
-12.700000
0
(from the "Wizard of OZ")
 
AFTER:
(from the "Wizard of OZ")
bears, oh my!
lions, tigers, and
-12.700000
0
77444
 
</pre>
 
=={{header|APL}}==
Line 903 ⟶ 985:
BEFORE: x=[lions, tigers, and]; y=[bears, oh my!]; z=[(from the "Wizard of OZ")]
AFTER: x=[(from the "Wizard of OZ")]; y=[bears, oh my!]; z=[lions, tigers, and]</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight lang=easylang>
proc sort3 . a b c .
if a > c
swap a c
.
if b > c
swap b c
.
if a > b
swap a b
.
.
x = 77444
y = -12
z = 0
sort3 x y z
print x & " " & y & " " & z
#
proc sort3str . a$ b$ c$ .
if strcmp a$ c$ > 0
swap a$ c$
.
if strcmp b$ c$ > 0
swap b$ c$
.
if strcmp a$ b$ > 0
swap a$ b$
.
.
x$ = "lions, tigers, and"
y$ = "bears, oh my!"
z$ = "(from the \"Wizard of OZ\")"
sort3str x$ y$ z$
print x$
print y$
print z$
</syntaxhighlight>
 
 
=={{header|EDSAC order code}}==
Line 956 ⟶ 1,078:
 
=={{header|Elena}}==
ELENA 56.0x :
<syntaxhighlight lang="elena">import extensions;
Line 1,355 ⟶ 1,477:
Y = 9.0099999999999998E+000
Z = 1.2340000000000000E+001</pre>
 
=={{header|Frink}}==
The following sorts the values in the variables x, y, and z and sets the sorted values back to the variables.
 
<syntaxhighlight lang="frink">x = 77444
y = -12
z = 0
 
[x,y,z] = sort[[x,y,z]]
println["x = $x"]
println["y = $y"]
println["z = $z"]</syntaxhighlight>
{{out}}
<pre>
x = -12
y = 0
z = 77444
</pre>
 
=={{header|Go}}==
Line 3,125 ⟶ 3,265:
bears, oh my!
lions, tigers, and</pre>
 
=={{header|RPL}}==
{{works with|HP|48}}
≪ → x y z
≪ x y z 3 →LIST SORT LIST→ DROP
≫ ≫ '<span style="color:blue">SORT3</span>' STO
 
"lions, tigers, and" "bears, oh my!" "(from the 'Wizard of OZ')" <span style="color:blue">SORT3</span>
77444 -12 9 <span style="color:blue">SORT3</span>
{{out}}
<pre>
6: "bears, oh my!"
5: "lions, tigers, and"
4: "(from the 'Wizard of OZ')"
3: -12
2: 9
1: 77444
</pre>
 
=={{header|Ruby}}==
Line 3,462 ⟶ 3,620:
{{libheader|Wren-sort}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./sort" for Sort
import "./fmt" for Fmt
 
var sort3 = Fn.new { |x, y, z|
490

edits