Created
January 14, 2020 18:04
-
-
Save abhilash0001/0b710613ece6a730d37cd6837a20f44a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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