Generic swap: Difference between revisions
Content added Content deleted
(Jakt) |
|||
Line 1,852: | Line 1,852: | ||
V2 |
V2 |
||
cat</syntaxhighlight> |
cat</syntaxhighlight> |
||
=={{header|Jakt}}== |
|||
<syntaxhighlight lang="jakt"> |
|||
fn swap<T>(anon a: &mut T, anon b: &mut T) { |
|||
let temporary = *a |
|||
*a = *b |
|||
*b = temporary |
|||
} |
|||
fn main() { |
|||
mut a = "Hello" |
|||
mut b = "World" |
|||
println("{} {}", a, b) |
|||
swap(&mut a, &mut b) |
|||
println("{} {}", a, b) |
|||
mut c = 1 |
|||
mut d = 2 |
|||
println("{} {}", c, d) |
|||
swap(&mut c, &mut d) |
|||
println("{} {}", c, d) |
|||
} |
|||
</syntaxhighlight> |
|||
=={{header|Java}}== |
=={{header|Java}}== |