Jump to content

Generic swap: Difference between revisions

no edit summary
(Better D entry)
No edit summary
Line 1,452:
 
Also, the sub will fail if one arg is a string containing non-numeric data and the other arg is numeric.
 
=={{header|XPL0}}==
The name Swap is normally used to call an intrinsic routine that swaps
bytes in an integer. Thus Exch is used here instead. A and B must both be
the same size.
 
<lang XPL0>include c:\cxpl\codes;
 
proc Exch(A, B, S);
char A, B, S;
int I, T;
for I:= 0 to S-1 do
[T:= A(I); A(I):= B(I); B(I):= T];
 
 
real X, Y;
[X:= 3.0; Y:= 4.0;
Exch(addr X, addr Y, 8);
RlOut(0, X); RlOut(0, Y); CrLf(0);
]</lang>
 
Output:
<pre>
4.00000 3.00000
</pre>
 
=={{header|Yorick}}==
772

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.