Last active
August 29, 2015 14:08
-
-
Save kartikkukreja/77878c1d9c4b0e407b37 to your computer and use it in GitHub Desktop.
Solution permutation with sorting
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
bool order(int x, int y) { | |
int xr = x ^ y, lowest_diff_bit = xr&(-xr); | |
return (x & lowest_diff_bit); | |
} | |
void print_sequence(int N) { | |
int* A = new int[N]; | |
for (int i = 0; i < N; ++i) | |
A[i] = i+1; | |
sort(A, A + N, order); | |
for (int i = 0; i < N; ++i) | |
printf("%d ", A[i]); | |
printf("\n"); | |
delete[] A; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment