Exemple #1
0
        public static void Main()
        {
            MyCustomList <string> elements = new MyCustomList <string>();

            string command = Console.ReadLine();

            while (command != "END")
            {
                string[] commandArgs = command.Split(' ');

                switch (commandArgs[0])
                {
                case "Add": elements.Add(commandArgs[1]); break;

                case "Remove": elements.Remove(int.Parse(commandArgs[1])); break;

                case "Contains": elements.Contains(commandArgs[1]); break;

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

                case "Greater": elements.CountGreaterThan(commandArgs[1]); break;

                case "Max": elements.Max(); break;

                case "Min": elements.Min(); break;

                case "Print": elements.Print(); break;
                }
            }
        }
        public void InterpredCommand(string input)
        {
            var tokens  = input.Split(' ');
            var command = tokens[0];

            switch (command)
            {
            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.CountGreaterElements(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.Sort();
                break;
            }
        }