static void Main(string[] args) { CustomList <string> elements = new CustomList <string>(); string[] input = Console.ReadLine().Split(' '); while (input[0] != "END") { switch (input[0]) { case "Add": elements.Add(input[1]); break; case "Print": elements.Print(); break; case "Remove": elements.Remove(int.Parse(input[1])); break; case "Contains": Console.WriteLine(elements.Contains(input[1])); break; case "Swap": int index1 = int.Parse(input[1]); int index2 = int.Parse(input[2]); elements.Swap(index1, index2); break; case "Greater": Console.WriteLine(elements.CountGreaterThan(input[1])); break; case "Max": Console.WriteLine(elements.Max()); break; case "Min": Console.WriteLine(elements.Min()); break; case "Sort": Sorter.Sort(elements); break; } input = Console.ReadLine().Split(' '); } }
public static void Main() { string input; string element; var customList = new CustomList <string>(); while ((input = Console.ReadLine()) != "END") { var commandArgs = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var command = commandArgs[0]; switch (command) { case "Add": customList.Add(commandArgs[1]); break; case "Remove": customList.Remove(int.Parse(commandArgs[1])); break; case "Contains": element = commandArgs[1]; Console.WriteLine(customList.Contains(element)); break; case "Swap": var firstIndex = int.Parse(commandArgs[1]); var secondIndex = int.Parse(commandArgs[2]); customList.Swap(firstIndex, secondIndex); break; case "Greater": element = commandArgs[1]; Console.WriteLine(customList.CountGreaterThan(element)); break; case "Max": Console.WriteLine(customList.Max()); break; case "Min": Console.WriteLine(customList.Min()); break; case "Print": Console.WriteLine(customList.Print()); break; } } }
private void ExecuteCommand(string[] commandStrings) { var command = commandStrings[0]; switch (command) { case "Add": var elementToAdd = commandStrings[1]; CustomList.Add(elementToAdd); break; case "Remove": var indexToRemove = int.Parse(commandStrings[1]); CustomList.Remove(indexToRemove); break; case "Contains": var containsString = commandStrings[1]; CustomList.Contains(containsString); break; case "Swap": var indexOne = int.Parse(commandStrings[1]); var indexTwo = int.Parse(commandStrings[2]); CustomList.Swap(indexOne, indexTwo); break; case "Greater": var element = commandStrings[1]; CustomList.Greater(element); break; case "Max": CustomList.Max(); break; case "Min": CustomList.Min(); break; case "Print": CustomList.Print(); break; case "Sort": this.CustomList = Sorter.Sort(CustomList); break; } }
public void ParseCommand(string input) { var tokens = input.Split(' '); var command = tokens[0]; switch (command) { case "Add": var element = tokens[1]; list.Add(element); break; case "Remove": var index = int.Parse(tokens[1]); list.Remove(index); break; case "Contains": element = tokens[1]; Console.WriteLine(list.Contains(element)); break; case "Swap": var firstIndex = int.Parse(tokens[1]); var secondIndex = int.Parse(tokens[2]); list.Swap(firstIndex, secondIndex); break; case "Greater": element = tokens[1]; Console.WriteLine(list.CountGreaterThan(element)); break; case "Max": Console.WriteLine(list.Max()); break; case "Min": Console.WriteLine(list.Min()); break; case "Print": var printList = list.GetList(); Console.WriteLine(String.Join(Environment.NewLine, printList)); break; } }
public static void Main() { ICustomList <string> customList = new CustomList <string>(); string input = Console.ReadLine(); while (input != "END") { string[] inputArgs = input.Split(); string command = inputArgs[0]; string element = String.Empty; switch (command) { case "Add": element = inputArgs[1]; customList.Add(element); break; case "Remove": int index = int.Parse(inputArgs[1]); customList.Remove(index); break; case "Contains": element = inputArgs[1]; Console.WriteLine(customList.Contains(element)); break; case "Swap": int index1 = int.Parse(inputArgs[1]); int index2 = int.Parse(inputArgs[2]); customList.Swap(index1, index2); break; case "Greater": element = inputArgs[1]; Console.WriteLine(customList.CountGreaterThan(element)); break; case "Max": Console.WriteLine(customList.Max()); break; case "Min": Console.WriteLine(customList.Min()); break; case "Print": foreach (var item in customList) { Console.WriteLine(item); } break; case "Sort": customList.Sort(); break; default: break; } input = Console.ReadLine(); } }
static void Main() { string command = Console.ReadLine(); CustomList <string> clist = new CustomList <string>(); while (command != "END") { var tokens = command.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string commandType = tokens[0]; switch (commandType) { case "Add": { string value = tokens[1]; clist.Add(value); break; } case "Remove": { int index = int.Parse(tokens[1]); clist.Remove(index); break; } case "Contains": { string element = tokens[1]; Console.WriteLine(clist.Contains(element)); break; } case "Swap": { int index1 = int.Parse(tokens[1]); int index2 = int.Parse(tokens[2]); clist.Swap(index1, index2); break; } case "Greater": { string element = tokens[1]; Console.WriteLine(clist.CountGreaterThan(element)); break; } case "Max": { Console.WriteLine(clist.Max()); break; } case "Min": { Console.WriteLine(clist.Min()); break; } case "Print": { clist.Print(); break; } default: { break; } } command = Console.ReadLine(); } }