wu :: forums
« wu :: forums - Arrange n balls in an order »

Welcome, Guest. Please Login or Register.
Apr 28th, 2024, 5:15pm

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   microsoft
(Moderators: ThudnBlunder, william wu, Grimbal, Icarus, Eigenray, SMQ, towr)
   Arrange n balls in an order
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Arrange n balls in an order  (Read 2647 times)
digvesh
Newbie
*





   


Gender: male
Posts: 1
Arrange n balls in an order  
« on: Mar 16th, 2009, 7:44am »
Quote Quote Modify Modify

If you have n balls in an array, some of which are red, some are green and some are blue. Write an algorithm to arrange those n balls in such a way that all the balls with same color are together. i.e. first all red balls, then all green balls, then all blue balls.
 
Assume you have two predefined methods available:
1. GetColor( i ) : returns the color of the ball at index i in the array.
2. Swap( i, j ) : swaps the balls at indexs i and j in the array.
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: Arrange n balls in an order  
« Reply #1 on: Mar 16th, 2009, 7:59am »
Quote Quote Modify Modify

Here's one of the previous threads on the subject. (And there should be at least two others, somewhere)
 
 
[edit]
one, two, three
[/edit]
« Last Edit: Mar 16th, 2009, 8:09am by towr » IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
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