839 views
4 votes
Write bash script which takes array as an input of size 10 bind its even indexes to accept even values and odd indexes to accept odd numbers only. Print invalid input if given input is not valid.

1 Answer

2 votes

Answer:

Bash script which takes array as an input of size 10 bind its even indexes to accept even values and odd indexes to accept odd numbers only is explained below in detail.

Step-by-step explanation:

Even digits at an even table and odd digits at an odd table

Given an array of size n comprising an equal number of odd and even digits. The difficulty is to manage the numbers in such an approach that all the even digits get the even table and odd digits get the odd table. The necessitated auxiliary space is O(1).

Examples :

Input : arr[] = {8, 5, 1, 12, 6, 3}

Output : 3 6 1 12 5 8

Input : arr[] = {7, 9, 10, 19, 13, 18, 21, 20, 4, 14}

Output : 18 9 10 19 20 7 14 13 4 21

User Harlo Holmes
by
5.1k points