예제 #1
0
        static void Main(string[] args)
        {
            var command = Console.ReadLine();

            var collection = command.Split().Skip(1).ToArray(); // The First Command will always be "Create"

            var listyIterator = new ListyIterator <string>(collection);

            while ((command = Console.ReadLine()) != "END")
            {
                switch (command)
                {
                case "Print":
                    try
                    {
                        listyIterator.Print();
                    }
                    catch (InvalidOperationException ioe)
                    {
                        Console.WriteLine(ioe.Message);
                    }
                    break;

                case "PrintAll":
                    try
                    {
                        listyIterator.PrintAll();
                    }
                    catch (InvalidOperationException ioe)
                    {
                        Console.WriteLine(ioe.Message);
                    }
                    break;

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

                case "HasNext":
                    Console.WriteLine(listyIterator.HasNext());
                    break;
                }
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            var createCommand     = Console.ReadLine().Split();
            var initialCollection = new string[createCommand.Length - 1];

            for (int i = 1; i < createCommand.Length; i++)
            {
                initialCollection[i - 1] = createCommand[i];
            }

            var listyIterator = new ListyIterator <string>(initialCollection);

            var nextCommand = Console.ReadLine();

            while (nextCommand != "END")
            {
                switch (nextCommand)
                {
                case "Move":
                    Console.WriteLine(listyIterator.Move());
                    break;

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

                case "HasNext":
                    Console.WriteLine(listyIterator.HasNext());
                    break;

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

                nextCommand = Console.ReadLine();
            }
        }