public static void Print(CustumStack custumStack) { foreach (var element in custumStack) { Console.WriteLine(element); } foreach (var element in custumStack) { Console.WriteLine(element); } }
public static void Main() { var custumStack = new CustumStack(); string input; while ((input = Console.ReadLine()) != "END") { var args = input .Split(new[] { ",", " " }, StringSplitOptions.RemoveEmptyEntries) .ToArray(); var command = args[0]; args = args .Skip(1) .ToArray(); try { switch (command) { case "Push": custumStack.Push(args.Select(int.Parse).ToArray()); break; case "Pop": custumStack.Pop(); break; } } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(0); } } Print(custumStack); }
public static void Main() { var myCustumStack = new CustumStack <int>(); string[] input = Console.ReadLine().Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); while (input[0] != "END") { if (input[0] == "Push") { List <int> numbers = new List <int>(); for (int i = 1; i < input.Length; i++) { int currentNumber = int.Parse(input[i].Substring(0, 1)); numbers.Add(currentNumber); } myCustumStack.PushElement(numbers); } else if (input[0] == "Pop") { myCustumStack.PopElement(); } input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } foreach (var number in myCustumStack) { Console.WriteLine(number); } foreach (var number in myCustumStack) { Console.WriteLine(number); } }