Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
 private void ResetRootNode()
 {
     while (Root.Parent != null)
     {
         Root = Root.Parent;
     }
 }
Ejemplo n.º 3
0
 public void Apply(TreePlanted evnt)
 {
     Id = evnt.Id;
     Root = new Node(evnt.Value, null);
 }
Ejemplo n.º 4
0
 public void SetRightChild(Node root)
 {
     RightChild = root;
 }
Ejemplo n.º 5
0
 public void SetLeftChild(Node root)
 {
     LeftChild = root;
 }
Ejemplo n.º 6
0
 public Node(int value, Node parent)
 {
     Parent = parent;
     Value = value;
     Id = Guid.NewGuid();
 }