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 ChoudharyRank #80 · 24.4K reputationPosted May 7, 2016, 9:02 AM EDT
sachith wickramaarachchi79 reputationPosted May 7, 2016, 11:13 PM EDT
107
110
97
108
32
105
114
115
Nandini Shamdasani7 reputationPosted Mar 12, 2018, 3:06 AM EDT