static void Main(string[] args) { ListyIterator <string> listyIterator = null; while (true) { string command = Console.ReadLine(); if (command == "END") { break; } string[] tokens = command.Split(); string action = tokens[0]; if (action == "Create") { listyIterator = new ListyIterator <string>(tokens.Skip(1).ToList()); } else if (action == "Move") { Console.WriteLine(listyIterator.Move()); } else if (action == "HasNext") { Console.WriteLine(listyIterator.HasNext()); } else if (action == "Print") { try { listyIterator.Print(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } }
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); } }
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(); } }
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); } }