void sort(int arrLenth, int arr[]){
int buf, index;
for (int i = 1; i < arrLenth; i++)
{
buf = arr[i];
index = i - 1;
while(index >= 0 && arr[index] < buf )
{
if(arr[i]%2!=0 && arr[index+1]%2!=0)
continue;
arr[index+1] = arr[index];
index--;
}
arr[index+1] = buf;
}
for (int i = 1; i < arrLenth; i++)
{
buf = arr[i];
index = i - 1;
while(index >= 0 && arr[index] > buf )
{
if(arr[i]%2==0 && arr[index+1]%2==0)
continue;
arr[index+1] = arr[index];
index--;
}
arr[index+1] = buf;
}
}
#include <stdio.h>
void insertodd(int arr[], int hi) {
int a = arr[hi];
for (int lo = hi - 1; lo >= 0; lo--) {
if (arr[lo] & 1) {
if (a < arr[lo]) {
arr[hi] = arr[lo];
hi = lo;
} else break;
}
arr[hi] = a;
}
}
void inserteven(int arr[], int hi) {
int a = arr[hi];
for (int lo = hi - 1; lo >= 0; lo--) {
if (arr[lo] && !(arr[lo] & 1)) {
if (a > arr[lo]) {
arr[hi] = arr[lo];
hi = lo;
} else break;
}
arr[hi] = a;
}
}
void customsort(int arr[], int len) {
for (int i = 1; i < len; i++) {
if (arr[i] & 1) insertodd(arr, i);
else if (arr[i]) inserteven(arr, i);
}
}
int main() {
int arr[6] = {1, 2, 5, 3, 0, 4};
customsort(arr, 6);
for (int i = 0; i < 6; i++)
printf("%d, ", arr[i]);
return 0;
}