Computer Science, asked by assrk93, 2 months ago

given an array of size n write the function to rearrange the numbers of the array in such a way that the even and odd numbers are arranged alternatively in increasing order

Answers

Answered by ItzBrainlyQueen01
62

Answer:

Explanation:

Initialize array

arr = [5, 2, 8, 7, 1];

temp = 0;

#Displaying elements of original array

print("Elements of original array: ");

for i in range(0, len(arr)):

print(arr[i], end=" ");

#Sort the array in ascending order

for i in range(0, len(arr)):

for j in range(i+1, len(arr)):

if(arr[i] > arr[j]):

temp = arr[i];

arr[i] = arr[j];

arr[j] = temp;

print();

#Displaying elements of the array after sorting

print("Elements of array sorted in ascending order: ");

for i in range(0, len(arr)):

print(arr[i], end=" ");

Similar questions