示例#1
0
        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();
            }
        }