static void Main(string[] args)
        {
            ListyIterator <string> collection = new ListyIterator <string>();

            while (true)
            {
                string command = Console.ReadLine();
                if (command == "END")
                {
                    break;
                }
                else
                {
                    string[] parts = command.Split(' ', StringSplitOptions.RemoveEmptyEntries);
                    DoCommands(parts, collection);
                }
            }
            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                string[] createCommand = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
                ListyIterator <string> collection;
                if (createCommand.Length > 1)
                {
                    collection = new ListyIterator <string>(createCommand.Skip(1).ToList());
                }
                else
                {
                    collection = new ListyIterator <string>();
                }
                string input = Console.ReadLine().ToLower();
                while (input != "end")
                {
                    switch (input)
                    {
                    case "print":
                        collection.Print();
                        break;

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

                    case "move":
                        Console.WriteLine(collection.Move());
                        break;

                    case "printall":
                        collection.PrintAll();
                        break;
                    }
                    input = Console.ReadLine().ToLower();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            string input        = Console.ReadLine();
            var    command      = input.Split().Skip(1).ToArray();
            var    listIterator = new ListyIterator <string>(command);

            while ((input = Console.ReadLine()) != "END")
            {
                switch (input)
                {
                case "Move":
                    Console.WriteLine(listIterator.Move());
                    break;

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

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

                case "PrintAll":
                    foreach (var item in listIterator)
                    {
                        Console.Write($"{item} ");
                    }

                    Console.WriteLine();
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            string[] data = Console.ReadLine()
                            .Split()
                            .Skip(1)
                            .ToArray();

            ListyIterator <string> list = new ListyIterator <string>(data);

            string input = Console.ReadLine();

            while (input != "END")
            {
                switch (input)
                {
                case "Move":
                    Console.WriteLine(list.Move());
                    break;

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

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

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

                    break;
                }

                input = Console.ReadLine();
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            List <string>          items = Console.ReadLine().Split().Skip(1).ToList();
            ListyIterator <string> list  = new ListyIterator <string>(items);

            string command = Console.ReadLine();

            while (command != "END")
            {
                switch (command)
                {
                case "HasNext":
                    Console.WriteLine(list.HasNext());
                    break;

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

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

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

                command = Console.ReadLine();
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            var command = Console.ReadLine();

            var elements = command.Split().Skip(1).ToList();

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

            while (command != "END")
            {
                if (command == "Print")
                {
                    try
                    {
                        listyIterator.Print();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else if (command == "Move")
                {
                    Console.WriteLine(listyIterator.Move());
                }
                else if (command == "HasNext")
                {
                    Console.WriteLine(listyIterator.HasNext());
                }
                else if (command == "PrintAll")
                {
                    foreach (var item in listyIterator)
                    {
                        Console.Write($"{item} ");
                    }
                    Console.WriteLine();
                }


                command = Console.ReadLine();
            }
        }
Exemplo n.º 7
0
        static void Main()
        {
            string input;

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

                    if (command == "Create")
                    {
                        string[] arr = arguments.Skip(1).ToArray();
                        store = new ListyIterator <string>(arr);
                    }
                    else if (command == "Print")
                    {
                        store.Print();
                    }
                    else if (command == "PrintAll")
                    {
                        store.PrintAll();
                    }
                    else if (command == "HasNext")
                    {
                        Console.WriteLine(store.HasNext());
                    }
                    else if (command == "Move")
                    {
                        Console.WriteLine(store.Move());
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine(ae.Message);
                }
            }
        }
Exemplo n.º 8
0
        public static void Main()
        {
            string command = string.Empty;
            ListyIterator <string> listyIterator = null;

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

                if (commandTokens[0] == "Create")
                {
                    listyIterator = new ListyIterator <string>(commandTokens.Skip(1).ToArray());
                }
                else if (commandTokens[0] == "Move")
                {
                    Console.WriteLine(listyIterator.Move());
                }
                else if (commandTokens[0] == "Print")
                {
                    try
                    {
                        listyIterator.Print();
                    }
                    catch (ArgumentException ae)
                    {
                        Console.WriteLine(ae.Message);
                    }
                }
                else if (commandTokens[0] == "PrintAll")
                {
                    listyIterator.PrintAll();
                }
                else if (commandTokens[0] == "HasNext")
                {
                    Console.WriteLine(listyIterator.HasNext());
                }
            }
        }
Exemplo n.º 9
0
        public static void Main(string[] args)
        {
            string command = Console.ReadLine();

            List <string>          elements      = command.Split().Skip(1).ToList();
            ListyIterator <string> listyIterator = new ListyIterator <string>(elements);

            try
            {
                while (command != "END")
                {
                    if (command == "Print")
                    {
                        listyIterator.Print();
                    }
                    else if (command == "Move")
                    {
                        bool result = listyIterator.Move();
                        Console.WriteLine(result);
                    }
                    else if (command == "HasNext")
                    {
                        bool result = listyIterator.HasNext();
                        Console.WriteLine(result);
                    }
                    else if (command == "PrintAll")
                    {
                        Console.WriteLine(string.Join(" ", listyIterator));
                    }

                    command = Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        static void Main(string[] args)
        {
            var input = Console.ReadLine()
                        .Split(' ', StringSplitOptions.RemoveEmptyEntries)
                        .Skip(1)
                        .ToArray();

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

            string command = Console.ReadLine();

            while (command != "END")
            {
                if (command == "Move")
                {
                    Console.WriteLine(listyIterator.Move());
                }
                else if (command == "Print")
                {
                    listyIterator.Print();
                }
                else if (command == "HasNext")
                {
                    Console.WriteLine(listyIterator.HasNext());
                }
                else if (command == "PrintAll")
                {
                    foreach (var item in listyIterator)
                    {
                        Console.Write($"{item} ");
                    }
                    Console.WriteLine();
                }

                command = Console.ReadLine();
            }
        }
Exemplo n.º 11
0
        static void DoCommands(string[] parts, ListyIterator <string> collection)
        {
            switch (parts[0])
            {
            case "Create":
                if (parts.Length == 1)
                {
                    collection.List = new List <string>();
                }
                else
                {
                    parts           = parts.Skip(1).Take(parts.Length - 1).ToArray();
                    collection.List = new List <string>(parts);
                }
                break;

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

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

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

            case "PrintAll":
                collection.PrintAll();
                break;

            default:
                break;
            }
        }