Пример #1
0
        public static void Main()
        {
            var customList = new MyList <string>();

            string command;

            while ((command = Console.ReadLine()) != "END")
            {
                var args = command.Split(' ');

                switch (args[0])
                {
                case "Add":
                    customList.Add(args[1]);
                    break;

                case "Remove":
                    customList.Remove(int.Parse(args[1]));
                    break;

                case "Contains":
                    Console.WriteLine(customList.Contains(args[1]));
                    break;

                case "Swap":
                    customList.Swap(int.Parse(args[1]), int.Parse(args[2]));
                    break;

                case "Greater":
                    Console.WriteLine(customList.CountGreaterThan(args[1]));
                    break;

                case "Min":
                    Console.WriteLine(customList.Min());
                    break;

                case "Max":
                    Console.WriteLine(customList.Max());
                    break;

                case "Sort":
                    customList = Sorter.Sort(customList);
                    break;

                case "Print":
                    foreach (var element in customList)
                    {
                        Console.WriteLine(element);
                    }
                    break;
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            var list = new CustomList <string>();

            string command;

            while ((command = Console.ReadLine()) != "END")
            {
                string[] tokens = command.Split();

                switch (tokens[0])
                {
                case "Add":
                    list.Add(tokens[1]);
                    break;

                case "Remove":
                    list.Remove(int.Parse(tokens[1]));
                    break;

                case "Contains":
                    Console.WriteLine(list.Contains(tokens[1]));
                    break;

                case "Swap":
                    list.Swap(int.Parse(tokens[1]), int.Parse(tokens[2]));
                    break;

                case "Greater":
                    Console.WriteLine(list.CountGreaterThan(tokens[1]));
                    break;

                case "Max":
                    Console.WriteLine(list.Max());
                    break;

                case "Min":
                    Console.WriteLine(list.Min());
                    break;

                case "Print":
                    Console.WriteLine(list);
                    break;

                case "Sort":
                    Sorter.Sort(ref list);
                    break;

                default:
                    throw new ArgumentException();
                }
            }
        }
Пример #3
0
        public static void Main()
        {
            CustomList <string> myCustomList = new CustomList <string>();
            string inputLine;

            while ((inputLine = Console.ReadLine()) != "END")
            {
                var tokens = inputLine.Split(' ');

                switch (tokens[0])
                {
                case "Add":
                    myCustomList.Add(tokens[1]);
                    break;

                case "Remove":
                    myCustomList.Remove(int.Parse(tokens[1]));
                    break;

                case "Contains":
                    Console.WriteLine(myCustomList.Contains(tokens[1]));
                    break;

                case "Swap":
                    myCustomList.Swap(int.Parse(tokens[1]), int.Parse(tokens[2]));
                    break;

                case "Greater":
                    Console.WriteLine(myCustomList.CountGreaterThan(tokens[1]));
                    break;

                case "Min":
                    Console.WriteLine(myCustomList.Min());
                    break;

                case "Max":
                    Console.WriteLine(myCustomList.Max());
                    break;

                case "Sort":
                    myCustomList = Sorter.Sort(myCustomList);
                    break;

                case "Print":
                    foreach (var element in myCustomList)
                    {
                        Console.WriteLine(element);
                    }
                    break;
                }
            }
        }
Пример #4
0
        public static void Main()
        {
            var    customList = new CustomList <string>();
            string input;

            while ((input = Console.ReadLine()) != "END")
            {
                var command = input.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                switch (command[0].ToLower())
                {
                case "add":
                    var e = command[1];
                    customList.Add(e);
                    break;

                case "remove":
                    customList.Remove(int.Parse(command.Last()));
                    break;

                case "contains":
                    Console.WriteLine(customList.Contains(command[1]));
                    break;

                case "swap":
                    customList.Swap(int.Parse(command[1]), int.Parse(command[2]));
                    break;

                case "greater":
                    Console.WriteLine(customList.CountGreaterThan(command[1]));
                    break;

                case "max":
                    Console.WriteLine(customList.Max());
                    break;

                case "min":
                    Console.WriteLine(customList.Min());
                    break;

                case "sort":
                    customList.Elements = Sorter <string> .Sort(customList.Elements);

                    break;

                case "print":
                    Console.WriteLine(customList);
                    break;
                }
            }
        }