Last active
November 8, 2020 03:22
-
-
Save Alfex4936/d89fdc4c694a067c562f0992e2d2894e to your computer and use it in GitHub Desktop.
programming languages that support one-line swapping.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tuples | |
int a = 1; | |
int b = 2; | |
(a, b) = (b, a); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vars | |
std::swap(x,y); | |
// iterable | |
std::iter_swap(std::begin(array) + i, std::begin(array) + i + 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Crystal | |
A, B = A, B |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Go | |
A, B = A, B | |
A, B, C = B, A, C |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Julia | |
A, B = A, B | |
A, B, C = B, A, C |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://nim-lang.org/docs/system.html#swap%2CT%2CT | |
swap(a, b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python | |
A, B = A, B | |
A, B, C = B, A, C |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// swap method defined for &mut [T] | |
// https://doc.rust-lang.org/std/primitive.slice.html#method.swap | |
mutable_element.swap(0, 2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[array[j], array[j + 1]] = [array[j + 1], array[j]]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// V | |
A, B = A, B | |
A, B, C = B, A, C |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment