-
-
Save gdyrrahitis/92dd59993d1cc4b08797db6a9fd3fa2d 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
public static class Reverser | |
{ | |
public static string Reverse(string word) | |
{ | |
// Create the stack | |
var stack = new Stack<char>(); | |
// Insert each character from the string input in the stack | |
foreach (var character in word) | |
{ | |
stack.Push(character); | |
} | |
// Pop characters from the stack | |
// and store in a StringBuilder | |
var builder = new StringBuilder(); | |
while (!stack.IsEmpty) | |
{ | |
builder.Append(stack.Pop()); | |
} | |
return builder.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment