public static void Main() { var stack = new ArrayStack <int>(2); stack.Push(1); stack.Push(2); stack.Push(10); stack.Push(69); stack.Push(69); while (stack.Count > 0) { Console.WriteLine($"Pop: {stack.Pop()}"); } stack.Push(1); stack.Push(2); stack.Push(10); stack.Push(69); stack.Push(69); var popped = stack.Pop(); Console.WriteLine($"Popped element: {popped}"); var arr = stack.ToArray(); Console.WriteLine( "Stack to array representataion: {0}", string.Join(", ", arr)); }
public static void Main() { ArrayStack <int> linkedStack = new ArrayStack <int>(); for (int i = 1; i <= 10; i++) { linkedStack.Push(i); } try { for (int i = 0; i < 5; i++) { int popped = linkedStack.Pop(); Console.WriteLine(popped); } } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } Console.WriteLine(string.Join(", ", linkedStack.ToArray())); }