wu :: forums (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi)
riddles >> cs >> Array sorting
(Message started by: alexeigor on Mar 9th, 2008, 2:52pm)

Title: Array sorting
Post by alexeigor on Mar 9th, 2008, 2:52pm
There is an array of odd and even numbers. Now, sort them in such a way that the top portion of the array contains odd numbers, bottom portion contains even numbers. The odd numbers are to be sorted in descending order and the even numbers in ascending order. You are not allowed to use any extra array and it has to use a conventional sorting mechanism and should not do any pre or post processing.

Title: Re: Array sorting
Post by alexeigor on Mar 10th, 2008, 12:20am
Hint: [hideb]Define new comparator[/hideb]

Title: Re: Array sorting
Post by m_aakash on Mar 10th, 2008, 8:43am

on 03/09/08 at 14:52:12, alexeigor wrote:
There is an array of odd and even numbers. Now, sort them in such a way that the top portion of the array contains odd numbers, bottom portion contains even numbers. The odd numbers are to be sorted in descending order and the even numbers in ascending order. You are not allowed to use any extra array and it has to use a conventional sorting mechanism and should not do any pre or post processing.


use the idea of partitioning. based on lowest significant bit, separate the odd and even numbers.
sort the upper half in ascending order by partitioning using the remaining bits.
sort the lower half in descending order bye partitioning using the remaining bits.



Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board