private bool needTrack(BinaryNode node) { if (node == null) { return(false); } var tracking = LNodes.FindAll(e => e.Node.Num == node.Num); return(!tracking.Any()); }
private void PreorderMarker(BinaryNode current, int depth) { if (current == null) { return; } //condition to track current if (needTrack(current)) { Console.WriteLine($"adding {current.Num} at depth of {depth}"); if (depth < MaxDepth) { depth = MaxDepth; } LNodes.Add(LNode.Fac(current, depth)); if (needTrack(current.Left)) { PreorderMarker(current.Left, depth + 1); } else if (needTrack(current.Right)) { PreorderMarker(current.Right, depth + 1); } else { PreorderMarker(current.Parent, depth - 1); } } else { if (needTrack(current.Right)) { PreorderMarker(current.Right, depth + 1); } else { PreorderMarker(current.Parent, depth - 1); } } }