wu :: forums
« wu :: forums - Array sorting »

Welcome, Guest. Please Login or Register.
May 2nd, 2024, 1:22pm

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: Grimbal, ThudnBlunder, SMQ, Eigenray, towr, william wu, Icarus)
   Array sorting
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Array sorting  (Read 939 times)
alexeigor
Newbie
*





   


Posts: 45
Array sorting  
« on: Mar 9th, 2008, 2:52pm »
Quote Quote Modify 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 Quote Modify 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 Quote Modify 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
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

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