public IEnumerable <T> BreadthFirstTraverse() { var currentNode = Root; var queue = new TomQueue <BSTNode <T> >(); while (currentNode != null) { yield return(currentNode.Value); if (currentNode.Left != null) { queue.EnQueue(currentNode.Left); } if (currentNode.Right != null) { queue.EnQueue(currentNode.Right); } if (queue.Count > 0) { currentNode = queue.DeQueue(); } else { currentNode = null; } } }
public override void ReadInput(string input) { var parts = input.Split(':'); var command = parts[0]; switch (command) { case "E": _queue.EnQueue(ParseIntArray(parts[1])[0]); break; case "D": Output = _queue.DeQueue().ToString(); break; case "P": foreach (var i in _queue.Read()) { Output += i + " "; } break; default: Output = $"invalid input: {InstructionText}"; break; } }