How can i reverse a string using stack,here is my code.But there have an error...please help me to fix this problem,thank you :)
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- class Program
- {
- int top;
- int[] stack = new int[100];
- public void pop()
- {
- Console.WriteLine("{0}", stack[top--]);
- }
- public void push(char x)
- {
- if (top == 100 - 1)
- {
- Console.WriteLine("Stack is overflow");
- }
- else
- {
- stack[++top] = x;
- }
- }
- public void Main()
- {
- string word = "Sri Lanka";
- int len = word.Length;
- char[] array = word.ToCharArray();
- for (int i = 0; i < len; i++)
- {
- push(array[i]);
- }
- for (int i = 0; i < len; i++)
- {
- pop();
- }
- }
- }
- }
Pankaj Kumar ChoudharyPosted May 7, 2016, 1:02 PM
Nandini ShamdasaniPosted Mar 12, 2018, 7:06 AM
sachith wickramaarachchiPosted May 8, 2016, 3:13 AM
107
110
97
108
32
105
114
115