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