/// <summary> /// Combines left node and right node as new internal node and sets new node as parent node to both nodes. /// </summary> /// <param name="leftNode">left node</param> /// <param name="rightNode">right node</param> /// <returns>new internal node</returns> public static HuffmanTreeNode <T> InternalNodeCreate(HuffmanTreeNode <T> leftNode, HuffmanTreeNode <T> rightNode) { var internalNodeKey = leftNode.Frequency + rightNode.Frequency; var internalNode = new HuffmanTreeNode <T>(internalNodeKey, leftNode, rightNode); return(internalNode); }
/// <summary> /// Constructor to create internal node /// </summary> /// <param name="frequency">Frequency</param> /// <param name="leftChild">Left child</param> /// <param name="rightChild">Right child</param> public HuffmanTreeNode(int frequency, HuffmanTreeNode <T> leftChild, HuffmanTreeNode <T> rightChild) { Frequency = frequency; Leaf = false; leftChild.SetParent(this, false); rightChild.SetParent(this, true); }
/// <summary> /// Sets child as child node to this node /// </summary> /// <param name="childNode"></param> public void SetChild(HuffmanTreeNode <T> childNode) { if (childNode.IsRightChild) { RightChild = childNode; } else { LeftChild = childNode; } }
/// <summary> /// Sets given node as parent to this node and defines if this node is left or right of parent /// </summary> /// <param name="parent">Parent node</param> /// <param name="isRightChild">Is right child</param> /// <returns></returns> public HuffmanTreeNode <T> SetParent(HuffmanTreeNode <T> parent, bool isRightChild) { Parent = parent; IsRightChild = isRightChild; return(this); }