public LCRSNode AddChild(LCRSNode parent, object data) { if (parent is null) { return(null); } LCRSNode child = new LCRSNode(data); if (parent.LeftChild is null) { parent.LeftChild = child; } else { var node = parent.LeftChild; for ( ; node.RightSibling != null;) { node = node.RightSibling; } node.RightSibling = child; } return(child); }
public LCRSNode AddSibling(LCRSNode node, object data) { if (node is null) { return(null); } for ( ; node.RightSibling != null;) { node = node.RightSibling; } var sibling = new LCRSNode(data); node.RightSibling = sibling; return(sibling); }
private void PrintIndent(LCRSNode node, int indent) { if (node is null) { return; } // 현재 노드 출력 string pad = " ".PadLeft(indent); Console.WriteLine($"{pad}{node.Data}"); // 왼쪽 자식 // (자식이므로 indent 증가) PrintIndent(node.LeftChild, indent + 1); // 오른쪽 형제 // (형제이므로 동일 indent 사용) PrintIndent(node.RightSibling, indent); }
public LCRSTree(object rootData) { this.Root = new LCRSNode(rootData); }