본문 바로가기

자료구조

일반트리

더보기
        public Node AddChild(Node node, string data)
        {
            if (this.Root == null)
            {
                this.Root = new Node(data);
                return this.Root;
            }
            else
            {
                Node child = new Node(data);
                Node temp = this.Root;

                if (temp.Left == null)
                {
                    temp.Left = child;
                    return temp.Left;
                }

                temp = temp.Left;

                while (true)
                {
                    if (temp.Right == null)
                    {
                        temp.Right = child;
                        return temp.Right;
                    }
                    else
                    {
                        temp = temp.Right;
                    }
                }
            }
        }

'자료구조' 카테고리의 다른 글

사향트리 LeftSkewedTree  (0) 2021.12.28
LCRS트리 LevelOrder  (0) 2021.12.28
LCRS트리  (0) 2021.12.28
트리 LCRS Expression  (0) 2021.12.28
Queue 복습  (0) 2021.12.28