Exemplo n.º 1
0
        static void Main(string[] args)
        {
            List <string>          inputs = new List <string>();
            ListyIterator <string> list   = new ListyIterator <string>(inputs);

            string command = Console.ReadLine();

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

                switch (cmdArgs)
                {
                case "Create":
                    string[] input = command.Split().Skip(1).ToArray();
                    for (int i = 0; i < input.Length; i++)
                    {
                        inputs.Add(input[i]);
                    }
                    break;

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

                case "Print":
                    try
                    {
                        list.Print();
                    }
                    catch (IndexOutOfRangeException e)
                    {
                        Console.WriteLine(e.Message);;
                    }
                    break;

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

                case "PrintAll":
                    try
                    {
                        list.PrintAll();
                    }
                    catch (IndexOutOfRangeException e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    break;

                default:
                    break;
                }

                command = Console.ReadLine();
            }
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            ListyIterator <string> listIterator = null;
            string input = Console.ReadLine();

            while (input != "END")
            {
                string[] arguments = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string   command   = arguments[0];

                try
                {
                    switch (command)
                    {
                    case "Create":
                        string[] data = arguments.Skip(1).ToArray();
                        listIterator = new ListyIterator <string>(data);
                        break;

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

                    case "HasNext":
                        Console.WriteLine(listIterator.HasNext().ToString());
                        break;

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

                    default:
                        break;
                    }
                }
                catch (InvalidOperationException oe)
                {
                    Console.WriteLine(oe.Message);
                }
                input = Console.ReadLine();
            }
        }
Exemplo n.º 3
0
        public static void Main()
        {
            var listElements = Console.ReadLine()
                               .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                               .ToList();

            listElements.RemoveAt(0);

            ListyIterator <string> listy = new ListyIterator <string>(listElements);

            var command = Console.ReadLine()
                          .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            while (!command[0].Equals("END"))
            {
                try
                {
                    switch (command[0])
                    {
                    case "Move":
                        Console.WriteLine(listy.Move() ? "True" : "False");
                        break;

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

                    case "HasNext":
                        Console.WriteLine(listy.HasNext() ? "True" : "False");
                        break;
                    }
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine(ioe.Message);
                }


                command = Console.ReadLine()
                          .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            }
        }
Exemplo n.º 4
0
        public static void Main()
        {
            var    createCollection = Console.ReadLine().Split().Skip(1).ToArray();
            var    collection       = new ListyIterator <string>(createCollection);
            string command;

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

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

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

                    case "PrintAll":
                        foreach (var item in collection)
                        {
                            Console.Write(item + " ");
                        }
                        Console.WriteLine();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }