Skip to content

Instantly share code, notes, and snippets.

@kartikkukreja
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kartikkukreja/77878c1d9c4b0e407b37 to your computer and use it in GitHub Desktop.
Save kartikkukreja/77878c1d9c4b0e407b37 to your computer and use it in GitHub Desktop.
Solution permutation with sorting
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