Computer Science, asked by sirishakucharlapati9, 8 months ago

Input:The first line of the input consists of an integer num,representing the size of the list (N) the second line of the input consists of N space seperated integers representing the values of the list

Answers

Answered by magizhavan99
5

Explanation:

before the changes the elements of the list are

are[0]

Answered by pruthaasl
0

Answer:

#include<iostream>

using namespace std;

void swap(int *i, int *j)

{

   int temp = *i;

   *i = *j;

   *j = temp;

}

int seperateEvenAndOdd(int arr[], int size)

{

   int left = 0;

   int right = size - 1;

   while(left < right)

   {

       while(arr[left]%2 == 0 && left < right)

       {

           left++;

       }

   

while(arr[right]%2 == 1 && left < right)    

       {

           right--;

       }

if(left < right)

       {

           swap(&arr[left], &arr[right]);

           left++;

           right--;

       }

   }

}

int main()

{

   int arr_size;

   cin >> arr_size;

   int arr[arr_size];

   for(int i=0;i<arr_size;i++)

   {

       cin >> arr[i];

   }

   int i=0;

   seperateEvenAndOdd(arr,arr_size);

 

   for(i=0;i<arr_size;i++)

  cout << arr[i] << " ";

   return 0;

}

Explanation:

  • It is given that the size of the list is taken as the input.
  • Then the integers separated by space are taken as input.
  • The output prints the space-separated integers such that all the odd numbers of the list come after the even numbers.

#SPJ3

Similar questions