Пример #1
0
        private void BuildAVL(int data)
        {
            var node = new Node() { Data = data, LChild = null, RChild = null, Height = 0 };
            if (null == Root)
            {
                Root = node;
                return;
            }

            var current = Root;
            while (null != current)
            {
                if (data < current.Data)
                {
                    if (null == current.LChild)
                    {
                        current.LChild = node;
                        break;
                    }
                    else
                    {
                        current = current.LChild;
                    }
                }
                else
                {
                    if (null == current.RChild)
                    {
                        current.RChild = node;
                        break;
                    }
                    else
                    {
                        current = current.RChild;
                    }
                }
            }
        }