private static ListyIterator <string> ProcessCommand(ListyIterator <string> listyIterator, string[] inputTokens) { switch (inputTokens[0]) { case "Create": var elements = inputTokens.Skip(1).ToArray(); listyIterator = new ListyIterator <string>(elements); break; case "Move": Console.WriteLine(listyIterator.Move()); break; case "Print": listyIterator.Print(); break; case "PrintAll": Console.WriteLine(string.Join(" ", listyIterator)); break; case "HasNext": Console.WriteLine(listyIterator.HasNext()); break; default: throw new ArgumentException(); } return(listyIterator); }
public static void Main(string[] args) { string[] commands = Console.ReadLine() .Split(" ") .ToArray(); ListyIterator <string> listyIterator = null; while (commands[0]?.ToLower() != "end") { string command = commands[0]?.ToLower(); switch (command) { case "create": string[] values = commands.Skip(1).ToArray(); listyIterator = new ListyIterator <string>(values); break; case "move": Console.WriteLine(listyIterator.Move()); break; case "hasnext": Console.WriteLine(listyIterator.HasNext()); break; case "print": try { listyIterator.Print(); } catch (InvalidOperationException ioe) { Console.WriteLine(ioe.Message); } break; case "printall": try { foreach (var item in listyIterator) { Console.Write(item + " "); } Console.WriteLine(); } catch (InvalidOperationException ioe) { Console.WriteLine(ioe.Message); } break; } commands = Console.ReadLine() .Split(" ") .ToArray(); } }
static void Main(string[] args) { ListyIterator <string> listyIterator = new ListyIterator <string>(); string input; while ((input = Console.ReadLine()) != "END") { string[] command = input.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray(); switch (command[0]) { case "Create": listyIterator = new ListyIterator <string>(command.Skip(1).ToArray()); break; case "Move": Console.WriteLine(listyIterator.Move()); break; case "Print": try { listyIterator.Print(); } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } break; case "HasNext": Console.WriteLine(listyIterator.HasNext()); break; case "PrintAll": foreach (string item in listyIterator) { Console.Write(item + " "); } Console.WriteLine(); break; } } }
private static string ReadAndExecutesCommands() { StringBuilder sb = new StringBuilder(); string command = string.Empty; while (!(command = Console.ReadLine()).Equals("END")) { try { switch (command) { case "Move": sb.AppendLine(collection.Move().ToString()); break; case "HasNext": sb.AppendLine(collection.HasNext().ToString()); break; case "Print": sb.AppendLine(collection.Print()); break; case "PrintAll": foreach (string element in collection) { sb.Append($"{element} "); } sb.Remove(sb.Length - 1, 1).AppendLine(); break; default: break; } } catch (ArgumentException ae) { sb.AppendLine(ae.Message); } } return(sb.ToString().Trim()); }
static void Main(string[] args) { var create = Console.ReadLine().Split().Skip(1).ToArray(); var listy = new ListyIterator <string>(create); while (true) { string command = Console.ReadLine(); switch (command) { case "Move": Console.WriteLine(listy.Move()); break; case "Print": listy.Print(); break; case "HasNext": Console.WriteLine(listy.HasNext()); break; case "PrintAll": foreach (var item in listy) { Console.Write(item + " "); } Console.WriteLine(); break; case "END": return; } } }
public static void Main() { ListyIterator <string> listyIterator = null; string[] command = Console.ReadLine().Split(); while (command[0] != "END") { switch (command[0]) { case "Create": listyIterator = new ListyIterator <string>(command.Skip(1).ToArray()); break; case "Move": Console.WriteLine(listyIterator.Move()); break; case "HasNext": Console.WriteLine(listyIterator.HasNext()); break; case "Print": Console.WriteLine(listyIterator.Print()); break; case "PrintAll": Console.WriteLine(listyIterator.PrintAll()); break; } command = Console.ReadLine().Split(); } }