コード例 #1
0
        public static void Main(string[] args)
        {
            ListyIterator <string> collection = null;

            while (true)
            {
                try
                {
                    string[] command = Console.ReadLine().Split();
                    if (command[0] == "END")
                    {
                        break;
                    }
                    if (command[0] == "Create")
                    {
                        collection = new ListyIterator <string>(command.Skip(1).ToArray());
                    }
                    else if (command[0] == "HasNext")
                    {
                        Console.WriteLine(collection.HasNext());
                    }
                    else if (command[0] == "Move")
                    {
                        Console.WriteLine(collection.Move());
                    }
                    else if (command[0] == "Print")
                    {
                        collection.Print();
                    }
                    else if (command[0] == "PrintAll")
                    {
                        foreach (var item in collection)
                        {
                            Console.Write(item + " ");
                        }
                        Console.WriteLine();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            ListyIterator <string> listyIterator = null;
            var command = Console.ReadLine();

            while (command != "END")
            {
                try
                {
                    if (command.Contains("Create"))
                    {
                        var items = command.Split().Skip(1).ToList();
                        listyIterator = new ListyIterator <string>(items);
                    }
                    else if (command == "Print")
                    {
                        Console.WriteLine(listyIterator.Print());
                    }
                    else if (command == "HasNext")
                    {
                        Console.WriteLine(listyIterator.HasNext());
                    }
                    else if (command == "Move")
                    {
                        Console.WriteLine(listyIterator.Move());
                    }
                    else if (command == "PrintAll")
                    {
                        foreach (var item in listyIterator)
                        {
                            Console.Write(item + " ");
                        }
                        Console.WriteLine();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                command = Console.ReadLine();
            }
        }