using System; using System.Diagnostics;
namespace FixedLengthStackImplementationofStackofStringsArray
static readonly int MAX = 1000;
string[] stack = new string[MAX];
if (count > MAX) count = MAX;
internal bool Push(string data)
for (int i = 0; i <= MAX - 2; i++)
Console.WriteLine("Max array size exceeded. Roll off the end.");
Console.WriteLine("count=" + count + ", Push = " + data);
Console.WriteLine("count=" + count + ", Push = " + data);
string popValue = stack[MAX - 1];
Console.WriteLine("count = " + count + ", Pop = " + popValue);
for (int i = MAX - 1; i >= 1; i--)
Console.WriteLine("The topmost element of Stack is : {0}", Top());
internal void PrintStack()
Console.WriteLine("Printing Stack with {0} items:", count);
for (int i = MAX - 1; i >= 0; i--)
Console.Write("arr[" + i + "]=" + stack[i] + ",");
public static class Program
public static void Main()
Stopwatch sw = new Stopwatch();
Console.WriteLine("Pop/Push Array Test");
Console.WriteLine("Arr Len = " + s.Length().ToString());
Console.WriteLine("Top of stack is at index = " + (s.Length()-1).ToString());
Console.WriteLine("Item pushed in {0} ticks.", sw.ElapsedTicks);
Console.WriteLine("Item popped from Stack : {0}", s.Pop());
Console.WriteLine("Item popped from Stack : {0}", s.Pop());
Console.WriteLine("Item popped from Stack : {0}", s.Pop());
Console.WriteLine("Item popped from Stack : {0}", s.Pop());
Console.WriteLine("Item popped in {0} ticks.", sw.ElapsedTicks);