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