Пример #1
0
        public LCRSNode AddChild(LCRSNode parent, object data)
        {
            if (parent == null)
            {
                return(null);
            }

            LCRSNode child = new LCRSNode(data);

            if (parent.LeftChild == null)
            {
                parent.LeftChild = child;
            }
            else
            {
                var node = parent.LeftChild;
                while (node.RightSibling != null)
                {
                    node = node.RightSibling;
                }
                node.RightSibling = child;
            }

            return(child);
        }
Пример #2
0
        public LCRSNode AddSibling(LCRSNode node, object data)
        {
            if (node == null)
            {
                return(null);
            }

            while (node.RightSibling != null)
            {
                node = node.RightSibling;
            }

            var sibling = new LCRSNode(data);

            node.RightSibling = sibling;

            return(sibling);
        }
Пример #3
0
        private void PrintIndent(LCRSNode node, int indent)
        {
            if (node == null)
            {
                return;
            }

            // 현재노드 출력
            string pad = " ".PadLeft(indent);

            Console.WriteLine($"{pad}{node.Data}");

            // 왼쪽자식
            PrintIndent(node.LeftChild, indent + 1);

            // 오른쪽 형제
            PrintIndent(node.RightSibling, indent);
        }
Пример #4
0
 public LCRSTree(object rootData)
 {
     this.Root = new LCRSNode(rootData);
 }