public static void Main() { var customList = new CustomList <string>(); string command; while ((command = Console.ReadLine()) != "END") { var data = command.Split(); switch (data[0]) { case "Add": customList.Add(data[1]); break; case "Remove": customList.Remove(int.Parse(data[1])); break; case "Contains": customList.Contains(data[1]); break; case "Swap": customList.Swap(int.Parse(data[1]), int.Parse(data[2])); break; case "Greater": customList.Greater(data[1]); break; case "Max": customList.Max(); break; case "Min": customList.Min(); break; case "Sort": customList.Sort(); break; case "Print": customList.Print(); break; default: throw new ArgumentException("Invalid command!"); } } }
public static void Main(string[] args) { CustomList <string> elements = new CustomList <string>(); string command = Console.ReadLine(); while (command != "END") { string[] cmdArgs = command.Split(); string action = cmdArgs[0]; switch (action) { case "Add": elements.Add(cmdArgs[1]); break; case "Remove": elements.Remove(int.Parse(cmdArgs[1])); break; case "Contains": Console.WriteLine(elements.Contains(cmdArgs[1])); break; case "Swap": elements.Swap(int.Parse(cmdArgs[1]), int.Parse(cmdArgs[2])); break; case "Greater": int count = elements.CountGreatherThan(cmdArgs[1]); Console.WriteLine(count); break; case "Max": Console.WriteLine(elements.Max); break; case "Min": Console.WriteLine(elements.Min); break; case "Print": foreach (var element in elements.Elements) { Console.WriteLine(element); } break; case "Sort": elements.Sort(); break; default: break; } command = Console.ReadLine(); } }
static void Main(string[] args) { var input = Console.ReadLine(); var customList = new CustomList <string>(); while (input != "END") { var tokens = input.Split(); var command = tokens[0]; switch (command) { case "Add": var elementToAdd = tokens[1]; customList.Add(elementToAdd); break; case "Remove": var index = int.Parse(tokens[1]); customList.Remove(index); break; case "Contains": var element = tokens[1]; Console.WriteLine(customList.Contains(element)); break; case "Swap": var index1 = int.Parse(tokens[1]); var index2 = int.Parse(tokens[2]); customList.Swap(index1, index2); break; case "Greater": element = tokens[1]; Console.WriteLine(customList.CountGreaterThan(element)); break; case "Max": Console.WriteLine(customList.Max()); break; case "Min": Console.WriteLine(customList.Min()); break; case "Sort": customList.Sort(); break; case "Print": Console.WriteLine(customList); break; } input = Console.ReadLine(); } }
private static void Main(string[] args) { var line = Console.ReadLine(); CustomList <string> customList = new CustomList <string>(); while (line != "END") { var tokens = line.Split(); var command = tokens[0]; switch (command) { case "Add": customList.Add(tokens[1]); break; case "Remove": customList.Remove(int.Parse(tokens[1])); break; case "Contains": var count = customList.Contains(tokens[1]); Console.WriteLine(count); break; case "Swap": var firstIndex = int.Parse(tokens[1]); var secondIndex = int.Parse(tokens[2]); customList.Swap(firstIndex, secondIndex); break; case "Greater": var counter = customList.CountGreaterThan(tokens[1]); Console.WriteLine(counter); break; case "Max": var max = customList.Max(); Console.WriteLine(max); break; case "Min": var min = customList.Min(); Console.WriteLine(min); break; case "Sort": customList.Sort(); break; case "Print": foreach (var element in customList.Elements) { Console.WriteLine(element); } break; } line = Console.ReadLine(); } }