static void Main(string[] args) { var command = Console.ReadLine(); var collection = command.Split().Skip(1).ToArray(); // The First Command will always be "Create" var listyIterator = new ListyIterator <string>(collection); while ((command = Console.ReadLine()) != "END") { switch (command) { case "Print": try { listyIterator.Print(); } catch (InvalidOperationException ioe) { Console.WriteLine(ioe.Message); } break; case "Move": Console.WriteLine(listyIterator.Move()); break; case "HasNext": Console.WriteLine(listyIterator.HasNext()); break; } } }
static void Main(string[] args) { ListyIterator <string> listyIterator = new ListyIterator <string>(); string input = String.Empty; while ((input = Console.ReadLine()) != "END") { string[] cmdArgs = input.Split(); string command = cmdArgs[0]; try { switch (command) { case "Create": listyIterator = new ListyIterator <string>(cmdArgs.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; default: throw new InvalidOperationException("Invalid Operation!"); } } catch (Exception e) { Console.WriteLine(e.Message); } } }
static void Main(string[] args) { var createCommand = Console.ReadLine().Split(); var initialCollection = new string[createCommand.Length - 1]; for (int i = 1; i < createCommand.Length; i++) { initialCollection[i - 1] = createCommand[i]; } var listyIterator = new ListyIterator <string>(initialCollection); var nextCommand = Console.ReadLine(); while (nextCommand != "END") { switch (nextCommand) { case "Move": Console.WriteLine(listyIterator.Move()); break; case "Print": listyIterator.Print(); break; case "HasNext": Console.WriteLine(listyIterator.HasNext()); break; } nextCommand = Console.ReadLine(); } }
static void Main(string[] args) { List <string> create = Console.ReadLine().Split().ToList(); ListyIterator <string> listyterator = new ListyIterator <string>(); if (create.Count > 1) { create.RemoveAt(0); string[] array = create.ToArray(); listyterator.Create(array); } else { listyterator.Create(); } while (true) { try { string command = Console.ReadLine(); if (command == "END") { break; } else if (command == "Move") { Console.WriteLine(listyterator.Move()); } else if (command == "Print") { listyterator.Print(); } else if (command == "HasNext") { Console.WriteLine(listyterator.HasNext()); } else if (command == "PrintAll") { foreach (var item in listyterator) { Console.Write(item + " "); } Console.WriteLine(); } } catch (Exception exception) { Console.WriteLine(exception.Message); } } }
private static string CommandsExecution(ListyIterator <string> collection) { var sb = new StringBuilder(); var cmdArgs = Console.ReadLine().Split(); while (cmdArgs[0] != "END") { try { switch (cmdArgs[0]) { case "Move": sb.AppendLine(collection.Move().ToString()); break; case "Print": sb.AppendLine(collection.Print()); break; case "HasNext": sb.AppendLine(collection.HasNext().ToString()); break; case "PrintAll": foreach (var item in collection) { sb.Append($"{item} "); } sb.Remove(sb.Length - 1, 1); sb.AppendLine(); break; default: break; } } catch (ArgumentException ae) { sb.AppendLine(ae.Message); } cmdArgs = Console.ReadLine().Split(); } return(sb.ToString().Trim()); }
static void Main(string[] args) { List <string> create = Console.ReadLine().Split().ToList(); ListyIterator <string> listyterator = new ListyIterator <string>(); if (create.Count > 1) { create.RemoveAt(0); string[] array = create.ToArray(); listyterator.Create(array); } else { listyterator.Create(); } while (true) { string command = Console.ReadLine(); if (command == "END") { break; } else if (command == "Move") { Console.WriteLine(listyterator.Move()); } else if (command == "Print") { listyterator.Print(); } else if (command == "HasNext") { Console.WriteLine(listyterator.HasNext()); } } }