Consider an array (for example (1 3 2 4 6 12))of even number of elements like 2,4 or any number which is even . Need to arrange array in below order.First maximum First Minimum Second Max Second Min Third Max Third Min…. I have divided code into 4 parts.## Arrange elements in Descending order and create a blank array newlist of same length with value 0## arr=(1 3 2 4 6 12)len=${#arr[@]}k=0newlist=()lngthminusone=$(( $len -1))echo $lngthminusonewhile [ $k -lt $len ]doi=0value=0newlist+=$valuewhile [ $i -lt $lngthminusone ]doj=$(( $i + 1))if [ ${arr[i]}…
Tag: Modulus in shell scripting
zig-zag arrangement in Array
Consider an array a= (1 4 3 -1 10 6) of length N, so zig-zag arrangement of elements is arr[0] < arr[1] > arr[2] < arr[3] > arr[4] < . . . . arr[n-2] < arr[n-1] > arr[n] Here, first we need to run code which will sort the data in descending order .For this you can refer to this blog. Once you arranged the data in descending order, then use the below code to bring elements in zig-zag order. i=0DescArr=(10 6 4 3 1 -1) ## Array in desc…