reverse display of string using stacked array in data structure in c#

No.of Views1682
Bookmarked3 times
Downloads 
Votes0
By  poly666   On  16 Feb 2010 00:02:46
Tag : CSharp , Miscellaneous
reverse display of string using stacked array in data structure in c#
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 Introduction

C# Code


{codecitation class="brush: csharp; gutter: true;" width="650px"}

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication42
{
class Program
{
static void Main(string[] args)
{
string str;
Console.WriteLine("Enter a word");
/*We hv taken string input from the user*/
str = Console.ReadLine();
/*creating a char array */
char[] arr = new char[str.Length];
/*it will convert string in char and then allocate momery to it in array*/
arr = str.ToCharArray();
/*Stack is a system generic class delacred so that we can use
* push n pop functions of stack*/
/*here mystack is obj through which we r calling push n pop*/
Stack<char> mystack = new Stack<char>();
/*above stack is system defined class,char is the data type
and mystack is the object*/
for (int i = 0; i < str.Length; i++)
{
/*pushing(inserting) each elemnt stored in arr(array) in stack */
mystack.Push(arr[i]);
}
for (int i = 0; i < str.Length; i++)
{
/*Retreving elemnts from stack using Pop(deletion)*/
Console.Write(mystack.Pop());
}
Console.ReadLine();
}
}
}

{/codecitation}

Thank you

Bhandari

 
Sign Up to vote for this article
 
About Author
 
poly666
Occupation-Not Provided
Company-Not Provided
Member Type-Fresh
Location-Not Provided
Joined date-15 Jul 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top