Exemple #1
0
        static void Main(string[] args)
        {
            CustomList <string> customList = new CustomList <string>();

            string command = Console.ReadLine();

            while (command != "END")
            {
                string[] tokens = command.Split();
                switch (tokens[0])
                {
                case "Add": customList.Add(tokens[1]); break;

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

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

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

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

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

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

                case "Print": customList.Print(); break;
                }
                command = Console.ReadLine();
            }
        }
        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(' ');
            }
        }
Exemple #3
0
        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;
                }
            }
        }
Exemple #4
0
        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;
            }
        }
        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();
            }
        }