public static void Main() { var input = string.Empty; while ((input = Console.ReadLine()) != "END") { var tokens = input.Split(' '); var command = tokens[0]; switch (command) { case "Add": var element = tokens[1]; CommandInterpreter.Add(element); break; case "Remove": int index = int.Parse(tokens[1]); CommandInterpreter.Remove(index); break; case "Contains": element = tokens[1]; Console.WriteLine(CommandInterpreter.Contains(element)); break; case "Max": Console.WriteLine(CommandInterpreter.Max()); break; case "Min": Console.WriteLine(CommandInterpreter.Min()); break; case "Swap": var index1 = int.Parse(tokens[1]); var index2 = int.Parse(tokens[2]); CommandInterpreter.Swap(index1, index2); break; case "Greater": var element1 = tokens[1]; Console.WriteLine(CommandInterpreter.Greater(element1)); break; case "Print": Console.WriteLine(CommandInterpreter.Print()); break; case "Sort": CommandInterpreter.Sort(); break; } } }
private static void Main(string[] args) { var commandInterpreter = new CommandInterpreter <string>(new CustomList <string>()); while (true) { var input = Console.ReadLine().Split(); var commandName = input[0]; switch (commandName) { case "Add": { commandInterpreter.Add(input[1]); } break; case "Remove": { var index = int.Parse(input[1]); commandInterpreter.Remove(index); } break; case "Contains": { commandInterpreter.Contains(input[1]); } break; case "Swap": { var first = int.Parse(input[1]); var second = int.Parse(input[2]); commandInterpreter.Swap(first, second); } break; case "Greater": { commandInterpreter.Greater(input[1]); } break; case "Max": { commandInterpreter.Max(); } break; case "Min": { commandInterpreter.Min(); } break; case "Print": { commandInterpreter.Print(); } break; case "END": { commandInterpreter.END(); } break; default: { throw new ArgumentException("Invalid command!"); } } } }