Exemplo n.º 1
0
        static void Main(string[] args)
        {
            ListyIterator <string> listyIterator = null;

            string command;

            while ((command = Console.ReadLine()) != "END")
            {
                var tokens = command.Split();

                switch (tokens[0])
                {
                case "Create":
                    listyIterator = new ListyIterator <string>(tokens.Skip(1).ToArray());
                    break;

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

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

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

                case "PrintAll":

                    foreach (var item in listyIterator)
                    {
                        Console.Write(item + " ");
                    }

                    Console.WriteLine();
                    break;
                }
            }
        }
        static void Main(string[] args)
        {
            string token = Console.ReadLine();

            List <string> elements = token
                                     .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                                     .Skip(1)
                                     .ToList();

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

            string command = Console.ReadLine();

            while (command != "END")
            {
                if (command == "Print")
                {
                    try
                    {
                        listyIterator.Print();
                    }
                    catch (InvalidOperationException exception)
                    {
                        Console.WriteLine(exception.Message);
                    }
                }
                else if (command == "HasNext")
                {
                    bool result = listyIterator.HasNext();
                    Console.WriteLine(result);
                }
                else if (command == "Move")
                {
                    bool result = listyIterator.Move();
                    Console.WriteLine(result);
                }
                else if (command == "PrintAll")
                {
                    foreach (var element in elements)
                    {
                        Console.Write(element + " ");
                    }
                }

                command = Console.ReadLine();
            }
        }
Exemplo n.º 3
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();
            }
        }
Exemplo n.º 4
0
        public static void Main()
        {
            string input;
            var    listyIterator = new ListyIterator <object>();

            while ((input = Console.ReadLine()) != "END")
            {
                string[] args    = input.Split();
                string   command = args[0];
                args = args.Skip(1).ToArray();

                try
                {
                    switch (command)
                    {
                    case "Create":
                        listyIterator.Create(args);
                        break;

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

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

                    case "PrintAll":
                        Console.WriteLine(listyIterator.GetAllElements());
                        break;

                    case "HasNext":
                        Console.WriteLine(listyIterator.HasNext().ToString());
                        break;
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }
            }
        }
Exemplo n.º 5
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();
                }
            }
        }
Exemplo n.º 6
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()));
                }
            }
        }
        static void Main(string[] args)
        {
            string[] elements = Console.ReadLine().Split().Skip(1).ToArray();

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

            string command;

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

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

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

                    case "PrintAll":
                        Console.WriteLine(string.Join(' ', listyIterator));
                        break;
                    }
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }