Esempio n. 1
0
        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":
                    Console.WriteLine(list);
                    break;

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

                default:
                    throw new ArgumentException();
                }
            }
        }
Esempio n. 2
0
        static void Main()
        {
            CustomList <string> list = new CustomList <string>();


            string input;

            while ((input = Console.ReadLine()) != "END")
            {
                string[] tokens = input.Split();

                string command = tokens[0];
                switch (command)
                {
                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 "Sort":
                    Sorter.Sort(list);
                    break;

                case "Print":
                    Print(list);
                    break;
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var input = Console.ReadLine();

            var customList = new CustomList <string>();

            while (input != "END")
            {
                var tokens  = input.Split();
                var command = tokens[0];

                switch (command)
                {
                case "Add":
                    var elementToAdd = tokens[1];
                    customList.Add(elementToAdd);
                    break;

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

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

                case "Swap":
                    var index1 = int.Parse(tokens[1]);
                    var index2 = int.Parse(tokens[2]);

                    customList.Swap(index1, index2);

                    break;

                case "Greater":
                    element = tokens[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);
                    break;
                }
                input = Console.ReadLine();
            }
        }
Esempio n. 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":
                    {
                        for (int i = 0; i < customList.Count; ++i)
                        {
                            Console.WriteLine(customList[i]);
                        }
                        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();
        }
Esempio n. 5
0
        private static void Main(string[] args)
        {
            var line = Console.ReadLine();

            CustomList <string> customList = new CustomList <string>();

            while (line != "END")
            {
                var tokens  = line.Split();
                var command = tokens[0];

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

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

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

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

                    customList.Swap(firstIndex, secondIndex);
                    break;

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

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

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

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

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

                line = Console.ReadLine();
            }
        }