Exemple #1
0
        public static void Main()
        {
            var customList = new CustomList <string>();

            string command;

            while ((command = Console.ReadLine()) != "END")
            {
                var data = command.Split();
                switch (data[0])
                {
                case "Add": customList.Add(data[1]); break;

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

                case "Contains": customList.Contains(data[1]); break;

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

                case "Greater": customList.Greater(data[1]); break;

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

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

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

                case "Print": customList.Print(); break;

                default: throw new ArgumentException("Invalid command!");
                }
            }
        }
Exemple #2
0
        public static void Main()
        {
            CustomList <string> elements = new CustomList <string>();
            string command = Console.ReadLine();

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

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

                case "Contains":
                    Console.WriteLine(elements.Contains(cmdArgs[1]));
                    break;

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

                case "Greater":
                    int count = elements.CountGreatherThan(cmdArgs[1]);
                    Console.WriteLine(count);
                    break;

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

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

                case "Print":
                    foreach (var element in elements)
                    {
                        Console.WriteLine(element);
                    }
                    break;

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

                default:
                    break;
                }

                command = Console.ReadLine();
            }
        }
        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":
                    foreach (var item in list)
                    {
                        Console.WriteLine(item);
                    }
                    break;

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

                default:
                    throw new ArgumentException();
                }
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            var customList = new CustomList <string>();

            while (true)
            {
                string line = Console.ReadLine();
                if (line == "END")
                {
                    break;
                }

                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                try
                {
                    var    inputs        = line.Split(' ');
                    string commandResult = null;

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

                    case "Remove":
                    {
                        commandResult = customList.Remove(int.Parse(inputs[1]));
                        break;
                    }

                    case "Contains":
                    {
                        commandResult = customList.Contains(inputs[1]).ToString();
                        break;
                    }

                    case "Swap":
                    {
                        int firstIndex  = int.Parse(inputs[1]);
                        int secondIndex = int.Parse(inputs[2]);

                        customList.Swap(firstIndex, secondIndex);
                        break;
                    }

                    case "Greater":
                    {
                        commandResult = customList.CountGreaterThan(inputs[1]).ToString();
                        break;
                    }

                    case "Max":
                    {
                        commandResult = customList.Max();
                        break;
                    }

                    case "Min":
                    {
                        commandResult = customList.Min();
                        break;
                    }

                    case "Print":
                    {
                        foreach (var item in customList)
                        {
                            Console.WriteLine(item);
                        }
                        break;
                    }

                    case "Sort":
                    {
                        Sorter.Sort(customList);
                        break;
                    }

                    default: throw new Exception("Invalid command.");
                    }

                    if (commandResult != null)
                    {
                        Console.WriteLine(commandResult);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.ReadKey();
        }