示例#1
0
 public void Postorder(Bnode Root)
 {
     if (Root != null)
     {
         Postorder(Root.Left);
         Postorder(Root.Right);
         Console.Write(Root.Value + " ");
     }
 }
示例#2
0
        public bool Insert(object data)
        {
            Bnode NewNode = new Bnode()
            {
                Value = data
            };
            Bnode TempParent;

            if (Root.Value == null)
            {
                Root = NewNode;
                return(true);
            }
            else
            {
                Current = Root;

                while (true)
                {
                    TempParent = Current;
                    if (Convert.ToInt32(NewNode.Value) < Convert.ToInt32(Current.Value))
                    {
                        Current = Current.Left;
                        if (Current == null)
                        {
                            TempParent.Left = NewNode;
                            return(true);
                        }
                    }
                    else
                    {
                        Current = Current.Right;
                        if (Current == null)
                        {
                            TempParent.Right = NewNode;
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
示例#3
0
 public BinarySTree()
 {
     Root    = new Bnode();
     Current = Root;
 }
示例#4
0
 public Bnode()
 {
     Right = Left = null;
 }