Using a linear sort algorithm write in pseudo how you would
Using a linear sort algorithm, write in pseudo, how you would sort two colored balls: red and white, so that all white balls are first and all RED balls are last.
In other words make RWRRWWWR to WWWWRRRR
Using a linear sort algorithm, write in pseudo, how you would sort two colored balls: red and white, so that all white balls are first and all RED balls are last.
In other words make RWRRWWWR to WWWWRRRR
In other words make RWRRWWWR to WWWWRRRR
Solution
int start = 0;
int end = n;
while (start < end)
{
if (balls [end].colour == RED)
{
--end;
continue;
}
if (balls [start].colour == WHITE)
{
++start;
continue;
}
swap (balls [start], balls [end]);
}
