Author |
Topic: Array sorting (Read 951 times) |
|
alexeigor
Newbie
Posts: 45
|
|
Array sorting
« on: Mar 9th, 2008, 2:52pm » |
Quote Modify
|
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.
|
|
IP Logged |
|
|
|
alexeigor
Newbie
Posts: 45
|
|
Re: Array sorting
« Reply #1 on: Mar 10th, 2008, 12:20am » |
Quote Modify
|
Hint: hidden: | Define new comparator |
|
|
IP Logged |
|
|
|
m_aakash
Junior Member
Posts: 96
|
|
Re: Array sorting
« Reply #2 on: Mar 10th, 2008, 8:43am » |
Quote Modify
|
on Mar 9th, 2008, 2:52pm, 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.
|
|
IP Logged |
|
|
|
|