Today we are going to share a Python 3 program for pendulum arrangement of numbers. If you are a python beginner and want to start learning the python programming, then keep your close attention in this tutorial as I am going to share a Python 3 program for pendulum arrangement of numbers.
To increase your Python knowledge, practice all Python programs, here is a collection of 100+ Python problems with solutions.
Copy the below python program and execute it with the help of python compiler.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | /** * Python 3 program for pendulum arrangement of numbers */ def pendulumArrangement(arr, n): # sorting the elements arr.sort() # Auxiliary array to store output op = [0] * n # calculating the middle index mid = int((n-1)/2) j = 1 i = 1 op[mid] = arr[0] for i in range(1,mid+1): op[mid+i] = arr[j] j+=1 op[mid-i] = arr[j] j+=1 if (int(n%2) == 0): op[mid+i] = arr[j] print("Pendulum arrangement:") for i in range(0,n): print(op[i],end=" ") # Driver function input Array arr = [14, 6, 19, 21, 12] n = len(arr) pendulumArrangement(arr, n) |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.