Write the program to do the following:
Read in an integer n (which can be at most 50). Then read in n integers one by one and store them in an array data from index 0 to n-1. Now we want to rearrange the integers in data in the following way:
Find the maximum value in data and put it in the center of the array (that is at (n/2)), find the next largest value and put it to its right, then the next largest and place it to its left and so on alternating right and left until all integers in data are done.
For example, if the array is initially:
7,3,1,6,4,2,5 then after rearranging it becomes 1,3,5,7,6,4,2
However, since we have very little memory, you are not allowed to use any other array apart from data.
INPUT: Give the number of integers: 5 7,9,2,5,6 Original array : 7 9 2 5 6 Rearranged array : 2 6 9 7 5
Have something to say? Log in to comment on this post.