Esempio n. 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;

                case "Sort": customList.Sort(); break;
                }
                command = Console.ReadLine();
            }
        }
Esempio n. 2
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 "Sort":
                    customList.Sort();
                    break;

                case "Print":
                    Console.WriteLine(customList.Print());
                    break;
                }
            }
        }
Esempio n. 3
0
        public void Parse(string input)
        {
            var tokens  = input.Split();
            var command = tokens[0];

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

            case "remove":
            {
                var index = int.Parse(tokens[1]);
                list.Remove(index);
            }
            break;

            case "contains":
            {
                var contains = list.Contains(tokens[1]);
                Print(contains);
            }
            break;

            case "swap":
            {
                var index1 = int.Parse(tokens[1]);
                var index2 = int.Parse(tokens[2]);
                list.Swap(index1, index2);
            }
            break;

            case "greater":
            {
                var count = list.CountGreaterThan(tokens[1]);
                Print(count);
            }
            break;

            case "max":
            {
                Print(list.Max());
            }
            break;

            case "min":
            {
                Print(list.Min());
            }
            break;

            case "print":
            {
                Print(list);
            }
            break;

            case "sort":
            {
                list.Sort();
            }
            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":
                {
                    clist.Print();
                    break;
                }

                default:
                {
                    break;
                }
                }
                command = Console.ReadLine();
            }
        }