Пример #1
0
        public void Apply(LeafAdded evnt)
        {
            var value = evnt.Value;
            Node parent = null;

            while (Root != null)
            {
                parent = Root;
                if (value < Root.Value)
                {
                    Root = Root.LeftChild;
                }
                else
                {
                    Root = Root.RightChild;
                }
            }

            var newNode = new Node(value, parent);
            Root = newNode;

            if (parent != null && value > parent.Value)
            {
                parent.SetRightChild(newNode);
            }
            else if (parent != null && value < parent.Value)
            {
                parent.SetLeftChild(newNode);
            }

            ResetRootNode();
        }
Пример #2
0
 private void ResetRootNode()
 {
     while (Root.Parent != null)
     {
         Root = Root.Parent;
     }
 }
Пример #3
0
 public void Apply(TreePlanted evnt)
 {
     Id = evnt.Id;
     Root = new Node(evnt.Value, null);
 }
Пример #4
0
 public void SetRightChild(Node root)
 {
     RightChild = root;
 }
Пример #5
0
 public void SetLeftChild(Node root)
 {
     LeftChild = root;
 }
Пример #6
0
 public Node(int value, Node parent)
 {
     Parent = parent;
     Value = value;
     Id = Guid.NewGuid();
 }