static void Main(string[] args) { string input; CustomStack <int> customStack = new CustomStack <int>(); while ((input = Console.ReadLine()) != "END") { string[] split = input.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries); switch (split[0]) { case "Push": foreach (var number in split.Skip(1).Select(int.Parse).ToArray()) { customStack.Push(number); } break; case "Pop": if (customStack.Count == 0) { Console.WriteLine("No elements"); } else { customStack.Pop(); } break; } } foreach (var item in customStack) { Console.WriteLine(item); } foreach (var item in customStack) { Console.WriteLine(item); } }
static void Main(string[] args) { var list = new CustomStack <string>(); var input = Console.ReadLine(); while (input != "END") { var com = input.Split(new string[] { ", ", " " }, StringSplitOptions.RemoveEmptyEntries); var inputTokens = com.Skip(1).ToList(); try { switch (com[0]) { case "Push": list.Push(inputTokens); break; case "Pop": list.Pop(); break; default: break; } } catch (Exception ex) { Console.WriteLine(ex.Message); } input = Console.ReadLine(); } for (int i = 0; i < 2; i++) { Console.WriteLine(string.Join("\n", list)); } }