Arranging numbers in an Array
Write an algorithm to arrange an array such that the largest element comes first , second largest is at the end , third largest is the second from beginning and so on.
I thought that the array could be sorted first. Then, we could use array[i]=array[2*i] for the first half of the elements, storing the values at odd positions (assuming array starts at array[0]) in a second array. Then, the stored values can be written back at the end of the first array in the reverse order. But, here sorting is required initially and requires extra space for the second array. Could you suggest some method that is more efficient? 
Re: Arranging numbers in an Array
You can only swap two elements at a time, so just use one temp variable repeatedly to make the swap.

Re: Arranging numbers in an Array
Thanks.

All times are GMT +5.5. The time now is 23:26. 