static void Main(string[] args) { MyCustomStack <string> customStack = new MyCustomStack <string>(); string command = Console.ReadLine(); while (command != "END") { string[] commandSplit = command.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); if (commandSplit[0] == "Push") { for (int i = 1; i < commandSplit.Length; i++) { customStack.Push(commandSplit[i]); } } else if (commandSplit[0] == "Pop") { customStack.Pop(); } command = Console.ReadLine(); } foreach (var item in customStack) { Console.WriteLine(item); } }
public void TestStack() { var myStack = new MyCustomStack(30); myStack.Push(20); myStack.Push(34); myStack.Push(2); Assert.Equal(2, myStack.Peek()); myStack.Pop(); Assert.Equal(34, myStack.Peek()); myStack.Pop(); Assert.Equal(20, myStack.Pop()); Assert.True(myStack.IsEmpty()); Assert.Equal(0, myStack.Size()); Assert.Throws <InvalidOperationException>(() => { myStack.Pop(); }); }