[Solved] Sort elements by placing elements with odd number index first and even indexes in the end of an array in C [closed]


you can find a typical solution here
`

 #include<stdio.h> 
  void swap(int *a, int *b);

void segregateEvenOdd(int arr[], int size)
 {
    /* Initialize left and right indexes */
     int left = 0, right = size-1;
while (left < right)
{
    /* Increment left index while we see 0 at left */
    while (arr[left]%2 == 0 && left < right)
        left++;

    /* Decrement right index while we see 1 at right */
    while (arr[right]%2 == 1 && left < right)
        right--;

    if (left < right)
    {
        /* Swap arr[left] and arr[right]*/
        swap(&arr[left], &arr[right]);
        left++;
        right--;
       }
      }
    }

 /* UTILITY FUNCTIONS */
void swap(int *a, int *b)
 {
   int temp = *a;
   *a = *b;
   *b = temp;
 }

    int main()
    {
       int arr[] = {12, 34, 45, 9, 8, 90, 3};
       int arr_size = sizeof(arr)/sizeof(arr[0]);
       int i = 0;

       segregateEvenOdd(arr, arr_size);

       printf("Array after segregation ");
       for (i = 0; i < arr_size; i++)
       printf("%d ", arr[i]);

      return 0; 
   }

` Link for the answer

2

solved Sort elements by placing elements with odd number index first and even indexes in the end of an array in C [closed]