Esempio n. 1
0
        static void Main(string[] args)
        {
            ListyIterator <string> list = new ListyIterator <string>();

            string[] command = Console.ReadLine().Split();

            while (command[0] != "END")
            {
                try
                {
                    switch (command[0])
                    {
                    case "Create":
                        list.Create(command.Skip(1).ToArray());
                        break;

                    case "HasNext":
                        Console.WriteLine(list.HasNext().ToString());
                        break;

                    case "Move":
                        Console.WriteLine(list.Move().ToString());
                        break;

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

                    case "PrintAll":
                        Console.WriteLine(string.Join(" ", list));
                        break;

                    default:
                        break;
                    }
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                command = Console.ReadLine().Split();
            }
        }
        public static void Main(string[] args)
        {
            ListyIterator <string> listyIterator = new ListyIterator <string>();

            string input = string.Empty;

            while ((input = Console.ReadLine()) != "END")
            {
                try
                {
                    if (input.Contains("Create"))
                    {
                        List <string> elements = input
                                                 .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                                                 .Skip(1)
                                                 .ToList();

                        listyIterator.Add(elements);
                    }
                    else if (input == "Move")
                    {
                        Console.WriteLine(listyIterator.Move());
                    }
                    else if (input == "HasNext")
                    {
                        Console.WriteLine(listyIterator.HasNext());
                    }
                    else if (input == "Print")
                    {
                        listyIterator.Print();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine()
                             .Split(' ');

            ListyIterator <string> iterator = new ListyIterator <string>(input
                                                                         .Skip(1)
                                                                         .ToList());

            input = Console.ReadLine()
                    .Split(' ');

            while (input[0] != "END")
            {
                string command = input[0];
                switch (command)
                {
                case "HasNext":
                    Console.WriteLine(iterator.HasNext());
                    break;

                case "Move":
                    Console.WriteLine(iterator.Move());
                    break;

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

                case "PrintAll":
                    iterator.PrintAll();
                    break;
                }

                input = Console.ReadLine()
                        .Split(' ');
            }
        }