Skip to content

Instantly share code, notes, and snippets.

@gdyrrahitis

gdyrrahitis/Reverser.cs Secret

Last active Nov 9, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.