Beispiel #1
0
        public static void Main()
        {
            string input = Console.ReadLine();

            ListyIterator <string> list = new ListyIterator <string>(input.Split(" ").Skip(1).ToArray());

            while (true)
            {
                input = Console.ReadLine();

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

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

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

                case "PrintAll":
                    Console.WriteLine(string.Join(" ", list));
                    break;

                case "END":
                    return;
                }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            ListyIterator <string> listyIterator = null;

            while (true)
            {
                string command = Console.ReadLine();
                if (command == "END")
                {
                    break;
                }

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

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

                case "PrintAll":
                    string message = String.Empty;
                    foreach (string element in listyIterator)
                    {
                        message += element + " ";
                    }

                    Console.WriteLine(message.TrimEnd());
                    break;

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

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

                default:
                    break;
                }
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            string[] createParams = Console.ReadLine().Split().Skip(1).ToArray();

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

            string command = Console.ReadLine();

            while (command != "END")
            {
                if (command == "Move")
                {
                    Console.WriteLine(listyIterator.Move());
                }

                else if (command == "Print")
                {
                    try
                    {
                        listyIterator.Print();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                else if (command == "HasNext")
                {
                    Console.WriteLine(listyIterator.HasNext());
                }

                else if (command == "PrintAll")
                {
                    try
                    {
                        listyIterator.PrintAll();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                command = Console.ReadLine();
            }
        }
        public static void Main()
        {
            var input = Console.ReadLine().Split();

            var list = new List <string>();

            if (input.Length > 1)
            {
                for (int i = 1; i < input.Length; i++)
                {
                    var currentElement = input[i];
                    list.Add(currentElement);
                }
            }

            var iterator = new ListyIterator <String>(list);

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

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

                if (command == "Move")
                {
                    Console.WriteLine(iterator.Move());
                }
                else if (command == "Print")
                {
                    iterator.Print();
                }
                else if (command == "HasNext")
                {
                    Console.WriteLine(iterator.HasNext());
                }
                else if (command == "PrintAll")
                {
                    Console.WriteLine(string.Join(" ", list));
                }
            }
        }
        static void Main()
        {
            var items = new ListyIterator <string>(Console.ReadLine().Split().Skip(1).ToArray());

            try
            {
                string line;
                while ((line = Console.ReadLine()) != "END")
                {
                    var tokens = line.Split();

                    switch (tokens[0])
                    {
                    case "HasNext":
                        Console.WriteLine(items.HasNext());
                        break;

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

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

                    case "PrintAll":
                        var sb = new StringBuilder();
                        foreach (var item in items)
                        {
                            sb.Append(item + " ");
                        }
                        Console.WriteLine(sb.ToString().TrimEnd());
                        break;
                    }
                }
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.Message);
            }
        }