示例#1
0
        static void Main(string[] args)
        {
            ListyIterator <string> listyIterator = new ListyIterator <string>();

            string input = String.Empty;

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

                try
                {
                    switch (command)
                    {
                    case "Create": listyIterator = new ListyIterator <string>(cmdArgs.Skip(1).ToArray()); break;

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

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

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

                    case "PrintAll": listyIterator.PrintAll(); break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
示例#2
0
        public static void Main(string[] args)
        {
            string[] inputArgs = Console.ReadLine().Split();

            string command = inputArgs[0];

            try
            {
                while (command != "END")
                {
                    switch (command)
                    {
                    case "Create":
                        customList = new ListyIterator <string>(inputArgs.Skip(1).ToArray());
                        break;

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

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

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

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

                    default:
                        break;
                    }

                    inputArgs = Console.ReadLine().Split();
                    command   = inputArgs[0];
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
示例#3
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;
                }
            }
        }
示例#4
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();
            }
        }