I have an array that I want to sort based on the value of one of the values in the array. The way I want to sort it is to evenly distribute the value I am searching for throughout the resulting array. For example –
Original array = [a,b,c,d,1,2,3,4]
I want to achieve – [a,1,b,2,c,3,d,4]
I can work out when to insert the numbers (total items / no. of numbers) = 2 so every 2nd item should be a number.
What is the easiest and most efficient way to do this type of sorting?
General solution:
Set
rto appropriate value and make sure that array length corresponds to that value. For instance ifris 2, the ratio of number of letters to number of digits is2:1and hence the length of the array,len, should be a multiple of 3.