Skip to content

Instantly share code, notes, and snippets.

@sundeepblue
Created January 30, 2014 06:44
Show Gist options
  • Save sundeepblue/8703730 to your computer and use it in GitHub Desktop.
Save sundeepblue/8703730 to your computer and use it in GitHub Desktop.
place odd number before even number in array
void place_odd_before_even(int A[], int n) {
if(n <= 1) return;
int left = 0, right = n-1;
while(left < right) {
while(left < right && A[left]%2 != 0) left++;
while(left < right && A[right]%2 == 0) right--;
if(left < right)
swap(A[left++], A[right--]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment