Ask user to enter his/her string and use stack structure to print out this after invert the string.
for example:
user string: computer
by using stack structure
print : retupmoc (inverted form of computer)
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sunny SharmaPosted Mar 20, 2014, 8:25 AM
static void Main(string[] args)
{
var inStr = Console.ReadLine();
var chars = new Stack<char>();
if (string.IsNullOrEmpty(inStr.Trim()))
{
Console.WriteLine("No characters entered");
return;
}
foreach (var c in inStr)
{
chars.Push(c);
}
while(chars.Count>0)
{
Console.Write(chars.Pop());
}
}
You should rather Google it first... lol... Happy hours! Enjoy the code!!