char str[100],t;
scanf("%s",str);
char ch='0';
int i=0,j=0;
while(j<strlen(str))
{
if(str[j]==ch)
{
SWAP(str[i],str[j],t);
i++;
}
j++;
}
ch='1';
j=i;
while(j<strlen(str))
{
if(str[j]==ch)
{
SWAP(str[i],str[j],t);
i++;
}
j++;
}
printf("%s\n",str);
On Sat, Sep 24, 2011 at 9:55 AM, Anup Ghatage <[email protected]> wrote:
> Is this like the segregating all the 1's to the right and the 0's to the
> left
> or am i missing something?
>
>
> On Sat, Sep 24, 2011 at 9:39 AM, VIHARRI <[email protected]> wrote:
>
>> You are given a string (consisting of 0's, 1's or 2's) where 0
>> represents a blue ball, 1 a
>> red ball, and 2 a black ball. Using only swap operations (counting
>> sort not allowed)
>> rearrange the string such that all blue balls are together on one
>> side, followed by all red
>> balls, and then all black balls. You can iterate through the string
>> only once.
>> Eg 102112011 should produce 001111122?
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> Anup Ghatage
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
*Dheeraj Sharma*
Comp Engg.
NIT Kurukshetra
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.