コード例 #1
0
        public static void Main(string[] args)
        {
            var input         = Console.ReadLine();
            var listylterator = new ListyIterator <string>(new List <string>());

            while (input != "END")
            {
                if (input.Contains("Create"))
                {
                    var createList = input.Split().ToArray();

                    if (createList.Length > 1)
                    {
                        for (int i = 1; i < createList.Length; i++)
                        {
                            listylterator.coolList.Add(createList[i]);
                        }
                    }
                }

                switch (input)
                {
                case "Move":
                    Console.WriteLine(listylterator.Move());
                    break;

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

                case "Print":
                    Console.WriteLine(listylterator.Print());
                    break;

                case "PrintAll":
                    Console.WriteLine(listylterator.PrintAll());
                    break;
                }

                input = Console.ReadLine();
            }
        }
コード例 #2
0
        static void Main()
        {
            var elements = Console.ReadLine()
                           .Split(' ')
                           .Skip(1)
                           .ToList();

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

            string command = String.Empty;

            while ((command = Console.ReadLine()) != "END")
            {
                if (command == "Move")
                {
                    Console.WriteLine(listyIterator.Move());
                }
                else if (command == "HasNext")
                {
                    Console.WriteLine(listyIterator.HasNext());
                }
                else if (command == "Print")
                {
                    try
                    {
                        listyIterator.Print();
                    }
                    catch (InvalidOperationException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else if (command == "PrintAll")
                {
                    listyIterator.PrintAll();
                }
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            string[] create = Console.ReadLine().Split(new[] { "Create", " " }, StringSplitOptions.RemoveEmptyEntries);

            ListyIterator <string> listyIterator = new ListyIterator <string>(create);

            while (true)
            {
                string command = Console.ReadLine();

                if (command == "END")
                {
                    break;
                }

                if (command == "HasNext")
                {
                    bool hasNext = listyIterator.HasNext();

                    Console.WriteLine(hasNext);
                }
                else if (command == "Move")
                {
                    bool canMove = listyIterator.Move();

                    Console.WriteLine(canMove);
                }
                else if (command == "Print")
                {
                    listyIterator.Print();
                }
                else if (command == "PrintAll")
                {
                    Console.WriteLine(string.Join(" ", listyIterator.PrintAll()));
                }
            }
        }