private static void DispatchCommands(string[] tokens) { if (tokens[0] == "Create") { List.Create(tokens); } else if (tokens[0] == "Move") { Console.WriteLine(List.MoveNext()); } else if (tokens[0] == "Print") { try { Console.WriteLine(List.Print()); } catch (Exception exception) { Console.WriteLine(exception.Message); } } else if (tokens[0] == "HasNext") { Console.WriteLine(List.HasNext()); } else if (tokens[0] == "PrintAll") { Console.WriteLine(List.PrintAll()); } }
public static void Main() { ListyIterator <string> listyIterator = new ListyIterator <string>(); string[] parts = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); listyIterator.Create(parts.Skip(1).ToArray()); string command = Console.ReadLine(); while (command != "END") { switch (command) { case "Move": Console.WriteLine(listyIterator.Move()); break; case "HasNext": Console.WriteLine(listyIterator.HasNext()); break; case "Print": listyIterator.Print(); break; case "PrintAll": listyIterator.PrintAll(); break; } command = Console.ReadLine(); } }
private static void ExecuteCommand(string command, ListyIterator <string> listyIterator) { switch (command) { case "Move": Console.WriteLine(listyIterator.Move()); break; case "Print": try { listyIterator.Print(); } catch (InvalidOperationException e) { Console.WriteLine(e.Message); } break; case "HasNext": Console.WriteLine(listyIterator.HasNext()); break; case "PrintAll": listyIterator.PrintAll(); break; } }
public static void Main() { var listIterator = new ListyIterator <string>(); string input; while ((input = Console.ReadLine()) != "END") { var commands = input.Split(); var currentCommand = commands[0]; switch (currentCommand) { case "Create": listIterator.Create(commands.Skip(1).ToArray()); break; case "Move": Console.WriteLine(listIterator.Move()); break; case "Print": listIterator.Print(); break; case "HasNext": Console.WriteLine(listIterator.HasNext()); break; case "PrintAll": Console.WriteLine(listIterator.PrintAll()); break; } } }
public void Interpret(string input) { string[] cmdArgs = input.Split(); if (cmdArgs[0] == "Create") { items = new ListyIterator <string>(cmdArgs.Skip(1).ToArray()); } switch (cmdArgs[0]) { case "Move": Console.WriteLine(items.MoveIndex()); break; case "Print": items.Print(); break; case "HasNext": Console.WriteLine(items.HasNext()); break; case "PrintAll": items.PrintAll(); break; } }
public static void Main() { var inputElements = Console.ReadLine().Split().Skip(1).ToList(); var elements = new ListyIterator <string>(inputElements); var isContinue = true; while (isContinue) { var command = Console.ReadLine(); switch (command) { case "Move": Console.WriteLine(elements.Move()); break; case "Print": Console.WriteLine(elements.Print()); break; case "HasNext": Console.WriteLine(elements.HasNext()); break; case "PrintAll": Console.WriteLine(elements.PrintAll()); break; case "END": isContinue = false; break; } } }
public static void Main() { List <string> createCommand = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); ListyIterator <string> list = new ListyIterator <string>(createCommand.GetRange(1, createCommand.Count - 1)); 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": list.Print(); break; case "PrintAll": list.PrintAll(); break; default: break; } input = Console.ReadLine(); } }
static void Main(string[] args) { ListyIterator <string> listyIterator = new ListyIterator <string>(new List <string>()); while (true) { var tokens = Console.ReadLine().Split().ToList(); try { switch (tokens[0]) { case "Create": List <string> names = new List <string>(); for (int i = 1; i < tokens.Count; i++) { names.Add(tokens[i]); } listyIterator = new ListyIterator <string>(names); break; case "Move": Console.WriteLine(listyIterator.Move()); break; case "HasNext": Console.WriteLine(listyIterator.HasNext()); break; case "Print": listyIterator.Print(); break; case "PrintAll": listyIterator.PrintAll(); break; case "END": Environment.Exit(0); break; default: throw new ArgumentException("Invalid Command !"); } } catch (Exception e) { Console.WriteLine(e.Message); } } }
public void Start() { string input = Console.ReadLine(); while (input != "END") { var inputLine = input.Split(' ').ToArray(); string command = inputLine[0]; var commands = inputLine.Skip(1).ToArray(); switch (command) { case "Create": listyIterator = new ListyIterator <string>(commands); break; case "Move": listyIterator.Move(); break; case "Print": try { listyIterator.Print(); } catch (Exception ex) { Console.WriteLine(ex.Message); } break; case "HasNext": listyIterator.HasNext(); break; case "PrintAll": try { listyIterator.PrintAll(); } catch (Exception ex) { Console.WriteLine(ex.Message); } break; default: break; } input = Console.ReadLine(); } }
private static void TryPrintAll <T>(ListyIterator <T> listyIterator) { try { listyIterator.PrintAll(); } catch (InvalidOperationException iopex) { Console.WriteLine(iopex.Message); } }
public void PrintAll_PrintsAll() { var listToUseToInitilize = new List <int>() { 1, 2, 3, 4, 5, 6, 7, 8 }; var listy = new ListyIterator <int>(listToUseToInitilize); var expected = "1 2 3 4 5 6 7 8"; var actual = listy.PrintAll(); Assert.That(actual, Is.EqualTo(expected)); }
static void Main(string[] args) { ListyIterator <string> listIterator = null; string input; while ((input = Console.ReadLine()) != "END") { string[] commandArgs = input.Split(new char[] { ' ' }); switch (commandArgs[0]) { case "Create": listIterator = new ListyIterator <string>(commandArgs.Skip(1).ToArray()); break; case "Move": Console.WriteLine(listIterator.Move()); break; case "HasNext": Console.WriteLine(listIterator.HasNext()); break; case "Print": try { listIterator.Print(); } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } break; case "PrintAll": try { listIterator.PrintAll(); } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } break; default: throw new ArgumentException(); } } }
static void Main(string[] args) { List <string> input = Console.ReadLine().Split().Skip(1).ToList(); ListyIterator <string> collectiion = new ListyIterator <string>(input); StringBuilder stringBuilder = new StringBuilder(); string command; try { while ((command = Console.ReadLine()) != "END") { switch (command) { case "Move": Console.WriteLine(collectiion.Move().ToString()); break; case "Print": Console.WriteLine(collectiion.Print().ToString());; break; case "HasNext": Console.WriteLine(collectiion.HasNext().ToString()); break; case "PrintAll": Console.WriteLine(collectiion.PrintAll()); break; default: break; } } } catch (ArgumentException e) { Console.WriteLine(e.Message); } }
public static void Main() { string input = Console.ReadLine(); string[] tokens = input.Split(); ListyIterator <string> listyIterator = new ListyIterator <string>(tokens.Skip(1).ToList()); while (input != "END") { tokens = input.Split(); string command = tokens[0]; switch (command) { case "HasNext": Console.WriteLine(listyIterator.HasNext()); break; case "Move": Console.WriteLine(listyIterator.Move()); break; case "Print": try { listyIterator.Print(); } catch (Exception exception) { Console.WriteLine(exception.Message); } break; case "PrintAll": try { listyIterator.PrintAll(); } catch (Exception exception) { Console.WriteLine(exception.Message); } break; } input = Console.ReadLine(); } }
public static void Main(string[] args) { var input = Console.ReadLine(); ListyIterator <string> listyIterator = null; while (input != "END") { var separated = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); switch (separated[0]) { case "Create": var elements = separated.Skip(1).ToArray(); listyIterator = new ListyIterator <string>(elements); break; case "Move": Console.WriteLine(listyIterator.Move()); break; case "HasNext": Console.WriteLine(listyIterator.HasNext()); break; case "Print": try { Console.WriteLine(listyIterator.Print()); } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } break; case "PrintAll": try { Console.WriteLine(listyIterator.PrintAll()); } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } break; } input = Console.ReadLine(); } }
public void Run() { var listy = new ListyIterator <string>(); try { var line = Console.ReadLine().Split().ToArray(); while (line[0] != "END") { var command = line[0]; switch (command) { case "Create": if (line.Length == 1) { listy.Create(); } listy.Create(line.Skip(1).ToArray()); break; case "Move": Console.WriteLine(listy.Move()); break; case "Print": Console.WriteLine(listy.Print()); break; case "PrintAll": Console.WriteLine(listy.PrintAll()); break; case "HasNext": Console.WriteLine(listy.HasNext()); break; } line = Console.ReadLine().Split().ToArray(); } } catch (ArgumentException e) { Console.WriteLine(e.Message); } }
static void Main() { var input = Console.ReadLine(); List <string> collection = input.Split().ToList(); collection.RemoveAt(0); var myList = new ListyIterator <string>(collection); while (input != "END") { switch (input) { case "HasNext": Console.WriteLine(myList.HasNext()); break; case "Move": Console.WriteLine(myList.Move()); break; case "Print": try { myList.Print(); } catch (Exception e) { Console.WriteLine(e); } break; case "PrintAll": try { myList.PrintAll(); } catch (Exception e) { Console.WriteLine(e); } break; } input = Console.ReadLine(); } }
static void Main() { string input; ListyIterator <string> list = null; while ((input = Console.ReadLine()) != "END") { var args = input.Split(); switch (args[0]) { case "Create": list = new ListyIterator <string>(new List <string>(args.Skip(1))); break; case "Move": Console.WriteLine(list.Move()); break; case "Print": try { list.Print(); } catch (Exception e) { Console.WriteLine(e.Message); } break; case "HasNext": Console.WriteLine(list.HasNext()); break; case "PrintAll": list.PrintAll(); break; } } }
static void Main() { string input = Console.ReadLine(); ListyIterator <string> listIterator = null; while (input != "END") { string[] commandTokens = input.Split(' ', StringSplitOptions.RemoveEmptyEntries); string command = commandTokens[0]; try { switch (command) { case "Create": string[] parameters = commandTokens.Skip(1).ToArray(); listIterator = new ListyIterator <string>(parameters); break; case "Move": Console.WriteLine(listIterator.Move()); break; case "Print": Console.WriteLine(listIterator.Print()); break; case "HasNext": Console.WriteLine(listIterator.HasNext()); break; case "PrintAll": Console.WriteLine(listIterator.PrintAll()); break; } } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } input = Console.ReadLine(); } }
static void Main() { string[] createList = Console.ReadLine() .Split(' ', StringSplitOptions.RemoveEmptyEntries); ListyIterator <string> listyIterator = new ListyIterator <string>(createList.Skip(1).ToArray()); string command = string.Empty; while ((command = Console.ReadLine()) != "END") { try { string result = string.Empty; switch (command) { case "Move": result = listyIterator.Move().ToString(); break; case "HasNext": result = listyIterator.HasNext().ToString(); break; case "Print": result = listyIterator.Print(); break; case "PrintAll": result = listyIterator.PrintAll(); break; default: break; } if (result != string.Empty) { Console.WriteLine(result); } } catch (ArgumentException argEx) { Console.WriteLine(argEx.Message); } } }
static void Main(string[] args) { string input = string.Empty; var listyIterator = new ListyIterator <string>(); while ((input = Console.ReadLine()) != "END") { string[] command = input.Split(); string currentCommand = command[0]; switch (currentCommand) { case "Create": if (command.Length > 1) { for (int i = 1; i < command.Length; i++) { listyIterator.Create(command[i]); } } break; case "HasNext": Console.WriteLine(listyIterator.HasNext()); break; case "Print": listyIterator.Print(); break; case "PrintAll": listyIterator.PrintAll(); break; case "Move": Console.WriteLine(listyIterator.Move()); break; default: break; } } }
static void Main() { var collection = Console.ReadLine().Split().ToList(); collection.RemoveAt(0); ListyIterator <string> iterator = new ListyIterator <string>(collection.ToArray()); string command; while ((command = Console.ReadLine()) != "END") { var result = ""; try { switch (command) { case "Move": result = iterator.Move().ToString(); break; case "Print": iterator.Print(); break; case "HasNext": result = iterator.HasNext().ToString(); break; case "PrintAll": iterator.PrintAll(); break; } if (result != "") { Console.WriteLine(result); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
static void Main() { ListyIterator <string> iterator = null; while (true) { var args = Console.ReadLine().Split(); var command = args[0]; if (command.Equals("END")) { break; } try { switch (command) { case "Create": iterator = new ListyIterator <string>(args.Skip(1).ToList()); break; case "Move": Console.WriteLine(iterator.Move()); break; case "Print": iterator.Print(); break; case "PrintAll": iterator.PrintAll(); break; case "HasNext": Console.WriteLine(iterator.HasNext()); break; } } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } } }
static void Main(string[] args) { string[] elements = Console.ReadLine().Split(); List <string> inputCollection = new List <string>(); for (int i = 1; i < elements.Length; i++) { inputCollection.Add(elements[i]); } ListyIterator <string> listy = new ListyIterator <string>(); listy.Create(inputCollection); string command = Console.ReadLine(); while (command != "END") { switch (command) { case "Move": Console.WriteLine(listy.Move()); break; case "HasNext": Console.WriteLine(listy.HasNext()); break; case "Print": try { listy.Print(); } catch (Exception e) { Console.WriteLine(e.Message); } break; case "PrintAll": listy.PrintAll(); break; } command = Console.ReadLine(); } }
static void Main(string[] args) { ListyIterator <string> listyIterator = null; string input; while ((input = Console.ReadLine()) != "END") { var lineParts = input.Split(" "); var command = lineParts[0]; switch (command) { case "Create": var collection = lineParts.Skip(1).ToArray(); listyIterator = new ListyIterator <string>(collection); break; case "Move": Console.WriteLine(listyIterator?.Move()); break; case "HasNext": Console.WriteLine(listyIterator?.HasNext()); break; case "Print": try { listyIterator.Print(); } catch (Exception ex) { Console.WriteLine(ex.Message); return; } break; case "PrintAll": listyIterator.PrintAll(); break; } } }
static void Main(string[] args) { ListyIterator <string> listyIterator = new ListyIterator <string>(); string input; while ((input = Console.ReadLine()) != "END") { try { string[] commandArgs = input.Split(); string command = commandArgs[0]; switch (command) { case "Create": listyIterator = new ListyIterator <string>(commandArgs.Skip(1).ToArray()); break; case "Move": Console.WriteLine(listyIterator.Move()); break; case "HasNext": Console.WriteLine(listyIterator.HasNext()); break; case "Print": listyIterator.Print(); break; case "PrintAll": listyIterator.PrintAll(); break; default: break; } } catch (Exception e) { Console.WriteLine(e.Message); } } }
static void Main(string[] args) { string input = string.Empty; ListyIterator <string> listly = null; while ((input = Console.ReadLine()) != "END") { var tokens = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList(); var command = tokens[0]; try { switch (command) { case "Create": listly = new ListyIterator <string>(tokens.Skip(1)); break; case "Move": Console.WriteLine(listly.Move()); break; case "Print": listly.Print(); break; case "HasNext": Console.WriteLine(listly.HasNext()); break; case "PrintAll": listly.PrintAll(); break; default: break; } } catch (InvalidOperationException e) { Console.WriteLine(e.Message); } } }
public static void Main(string[] args) { var elements = Console.ReadLine() .Split(' ') .Skip(1) .ToList(); ListyIterator <string> listy1 = new ListyIterator <string>(elements); var command = Console.ReadLine(); while (command != "END") { switch (command) { case "Move": Console.WriteLine(listy1.Move()); break; case "Print": try { listy1.Print(); } catch (IndexOutOfRangeException e) { Console.WriteLine(e.Message); } break; case "HasNext": Console.WriteLine(listy1.HasNext()); break; case "PrintAll": listy1.PrintAll(); break; } command = Console.ReadLine(); } }
static void Main(string[] args) { string input; var listy = new ListyIterator <string>(); while ((input = Console.ReadLine()) != "END") { try { var commandArgs = input.Split(); var command = commandArgs[0]; var element = commandArgs.Skip(1).ToList(); switch (command) { case "Create": listy.Create(element); break; case "Move": Console.WriteLine(listy.Move()); break; case "Print": listy.Print(); break; case "HasNext": Console.WriteLine(listy.HasNext()); break; case "PrintAll": listy.PrintAll(); break; } } catch (InvalidOperationException e) { Console.WriteLine(e.Message); } } }
static void Main(string[] args) { var createData = Console.ReadLine().Split().ToList(); createData.RemoveAt(0); var listy = new ListyIterator <string>(createData); var command = ""; while ((command = Console.ReadLine()) != "END") { try { switch (command) { case "HasNext": Console.WriteLine(listy.HasNext()); break; case "Print": listy.Print(); break; case "Move": Console.WriteLine(listy.Move()); break; case "PrintAll": listy.PrintAll(); break; default: break; } } catch (ArgumentException argEx) { Console.WriteLine(argEx.Message); } } }