node sort(node root)
{
node first;
int count=0;count1=0;count2=0;
for(first=root;first !=null;first=first->next)
{
if(first->data==1) count++;
if(first->data==2) count1++;
if(first->data==3) count2++;
}
first=root;
for(first;first !=null;first=first->next)
{
if(count>0)
{
first->data=1;
count--;
}
else if(count1>0)
{
first->data=2;
count1--;
}
else if(count2 >0)
{
first->data=3;
count2--;
}
return root;
}On 8/2/11, lokesh <[email protected]> wrote: > any other solution other than counting no. of 1s, 2s and 3s? > > -- > 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. > > -- 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.
