using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Stacks { class Program { static void Main(string[] args) { ArrayStack s1 = new ArrayStack(); string temp; s1.Push("easy"); s1.Push("this"); temp = (string)s1.Pop(); Console.Write(temp); s1.Push("is"); s1.Push("class"); while (s1.Count() != 0) { temp = (string)s1.Pop(); Console.Write(" " + temp); } Console.ReadLine(); } } class ArrayStack { public static int CAPACITY = 1000; private object[] S; private int top; public ArrayStack() { S = new object[CAPACITY]; top = -1; } public int Count() { return top + 1; } public void Push(object obj) { if (Count() == CAPACITY) Console.WriteLine("Stack Full"); else { S[++top] = obj; } } public object Pop() { if (Count() != 0) return S[top--]; else { Console.WriteLine("Stack Empty"); return null; } } public object Peek() { if (Count() != 0) return S[top]; else { Console.WriteLine("Stack Empty"); return null; } } public void Clear() { S = new object[CAPACITY]; top = -1; } } }