Пример #1
0
        public void Insert(NodeTree node)
        {
            if (Root == null)
            {
                Root = node;
                return;
            }

            NodeTree curNode = Root;

            while (true)
            {
                if(node.Data > curNode.Data && curNode.Right == null)
                {
                    curNode.Right = node;
                    return;
                }
                else if (node.Data > curNode.Data && curNode.Right != null)
                {
                    curNode = curNode.Right;
                }
                else if (node.Data < curNode.Data && curNode.Left == null)
                {
                    curNode.Left = node;
                    return;
                }
                else if (node.Data < curNode.Data && curNode.Left != null)
                {
                    curNode = curNode.Left;
                }
            }
        }
Пример #2
0
        public static void PreOrder(NodeTree node)
        {
            if (node == null)
                return;

            Console.WriteLine(node.Data);
            PreOrder(node.Left);
            PreOrder(node.Right);
        }
Пример #3
0
        public void InOrder(NodeTree node)
        {
            if (node == null)
                return;

            InOrder(node.Left);
            Console.WriteLine(node.Data);
            InOrder(node.Right);
        }