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 "Sort": customList.Sort(); break; case "Print": foreach (var item in customList) { Console.WriteLine(item); } ; 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; case "Sort": list = Sorter <string> .Sort(list); break; } }
public void ParseCommand(string input) { var tokens = input.Split(' '); var cmd = tokens[0]; switch (cmd) { case "Add": var element = tokens[1]; myList.Add(element); break; case "Remove": var index = int.Parse(tokens[1]); myList.Remove(index); break; case "Contains": element = tokens[1]; Console.WriteLine(myList.Contains(element)); break; case "Swap": var firstIndex = int.Parse(tokens[1]); var secondIndex = int.Parse(tokens[2]); myList.Swap(firstIndex, secondIndex); break; case "Greater": element = tokens[1]; Console.WriteLine(myList.CountGreaterThan(element)); break; case "Max": Console.WriteLine(myList.Max()); break; case "Min": Console.WriteLine(myList.Min()); break; case "Print": Console.WriteLine(myList.Print()); break; case "Sort": myList = Sorter <string> .Sort(myList); break; } }
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 "Sort": { clist.Sort(); break; } case "Print": { foreach (var element in clist) { Console.WriteLine(element); } // // clist.Print(); break; } default: { break; } } command = Console.ReadLine(); } }