public void ReverseWords(StringBuilder sb)
{
if (sb == null)
{
return ;
}
String tempStr = "";
int start = -1;
int end = -1;
//"My na"
for (int i = sb.Length -1; i >= 0; i--)
{
if (sb[i] == ' ')
{
if (end != -1)
{
start = i + 1;
// end = 4
// start = 3
while (start <= end)
{
tempStr = tempStr + sb[start];
start++;
}
start = -1;
end = -1;
}
tempStr = tempStr + sb[i];
}
else
{
if (end == -1)
{
end = i;
}
}
}
if (end != -1)
{
for (int i = 0; i <= end; i++)
{
tempStr = tempStr + sb[i];
}
}
Console.WriteLine(tempStr);
}