aspose file tools*
The moose likes Beginning Java and the fly likes sorting of large array  (containing either 5 or 10 )in one iteration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "sorting of large array  (containing either 5 or 10 )in one iteration" Watch "sorting of large array  (containing either 5 or 10 )in one iteration" New topic
Author

sorting of large array (containing either 5 or 10 )in one iteration

Prajwal Boloor
Greenhorn

Joined: Dec 19, 2004
Posts: 2
Hi All,

I am given a problem regarding int aray sorting.
Requirement:
1. array can be of any size
2. can contain only 5 or 10 as its values
3. has to be sorted in n = array.length iterations (i.e only one loop of n iteration).

can someone pls help me with the logic.
I am trying the same from my end, will update if i get through.

Thanks in advance,
Prajwal
prajwal.boloor@qwest.com
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not an advanced question. Moving...


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Not sure this is advanced Java. I haven't tried it, but...

1) Initialise an integer index P5 to just before the start of the array and another P10 to just after the end.

2) Move the P5 pointer forwards until it's on a 10 and P10 pointer backwards until it's on a 5.

3) If P5 has met or passed P10, STOP.

4) Swap the pointed-to numbers.

5) Go to 2


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Prajwal Boloor
Greenhorn

Joined: Dec 19, 2004
Posts: 2
Hey Thanks guys..
the above mentioned logic works
 
wood burning stoves
 
subject: sorting of large array (containing either 5 or 10 )in one iteration