Ejemplo n.º 1
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":
                    foreach (var item in customList)
                    {
                        Console.WriteLine(item);
                    }
                    ;
                    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":
                {
                    foreach (var element in clist)
                    {
                        Console.WriteLine(element);
                    }
                    //
                    // clist.Print();
                    break;
                }

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