public Node GetBrother(Node node) { if (node.Parent.Left == node) { return node.Parent.Right; } return node.Parent.Left; }
public void InsertLeftLeave(Node parent, Node node) { #region Defensive area if (parent == null) { throw new ArgumentNullException("parent", "Parent node can't be null."); } if (node == null) { throw new ArgumentNullException("node", "Inserted node can't be null."); } #endregion parent.Left = node; }
public Node GetRightChild(Node node) { return node.Right; }
public Node GetParent(Node node) { return node.Parent; }
public Node GetLeftChild(Node node) { return node.Left; }
private int NodeCount(Node node) { if (node == null) { return 0; } if (node.Left == null && node.Right == null) { return 1; } return (1 + (NodeCount(node.Left) + NodeCount(node.Right))); }
public Node RemoveRightLeaf(Node node) { if (!IsLeaf(node.Right)) { throw new InvalidOperationException("Removed node is not leaf and can't be removed."); } node.Right = null; return node; }
public bool IsLeaf(Node node) { return node.Left == null & node.Right == null; }
public void InsertRoot(Node node) { #region Defensive area if (node == null) { throw new ArgumentNullException("node", "Inserted node can't be null."); } #endregion Root = node; }