Created
December 17, 2019 08:27
-
-
Save EvanMu96/a5c008f07de60ea49852a5d98f048518 to your computer and use it in GitHub Desktop.
vector permutation
This file contains 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
tempalte <typename T> struct Vector<T>; | |
template <typename T> void _in_place_permute(Vector<T> & v) | |
{ | |
for(int i = v.size(); i > 0; i--) | |
swap(v[i-1], v[rand()%i); // swap a random element from [0, i) with i | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment