• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Prajwal Boloor
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Prajwal Boloor
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Thanks guys..
the above mentioned logic works
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic