Skip to content

Instantly share code, notes, and snippets.

@abhilash0001
Created January 14, 2020 18:04
Show Gist options
  • Save abhilash0001/0b710613ece6a730d37cd6837a20f44a to your computer and use it in GitHub Desktop.
Save abhilash0001/0b710613ece6a730d37cd6837a20f44a to your computer and use it in GitHub Desktop.
// input: Welcome to Csharp corner
// output: corner Csharp to Welcome
internal static void ReverseWordOrder(string str)
{
int i;
StringBuilder reverseSentence = new StringBuilder();
int Start = str.Length - 1;
int End = str.Length - 1;
while (Start > 0)
{
if (str[Start] == ' ')
{
i = Start + 1;
while (i <= End)
{
reverseSentence.Append(str[i]);
i++;
}
reverseSentence.Append(' ');
End = Start - 1;
}
Start--;
}
for (i = 0; i <= End; i++)
{
reverseSentence.Append(str[i]);
}
Console.WriteLine(reverseSentence.ToString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment