#include <stdio.h>

void swap(int *i, int *j)
{
    int temp = *i;
    *i = *j;
    *j = temp;
}
 
int seperateEvenAndOdd(int arr[], int size)
{
    // Initialize left and right indexes
    int left = 0;
    int right = size - 1;
     
    while(left < right)
    {
        // Increment left index till the number is even
        // num%2 == 0, condition to check even number
        while(arr[left]%2 == 0 && left < right)
        {
            left++;
        }
         
        // Decrement right index till the number is odd
        while(arr[right]%2 == 1 && left < right)
        {
            right--;
        }
         
        // Time to swap
        if(left < right)
        {
            swap(&arr[left], &arr[right]);
            left++;
            right--;
        }
    }
}

int main(void) {
	// your code goes here
	int arr[] = {4, 8, 15, 16, 23, 42};
	
	seperateEvenAndOdd(arr, 6);
	
	for (int i = 0; i<6;i++)
		printf("%d ", arr[i]);
	
	return 0;
}
