public static HeapNode Meld(HeapNode leftNode, HeapNode rightNode) { if (leftNode == null) { return(rightNode); } if (rightNode == null) { return(leftNode); } if (HeapNode.CompareTo(leftNode.val, rightNode.val) > 0) { var t = rightNode; rightNode = leftNode; leftNode = t; } leftNode.r = HeapNode.Meld(leftNode.r, rightNode); var t2 = leftNode.l; leftNode.l = leftNode.r; leftNode.r = t2; return(leftNode); }
/// <summary> /// 入れる /// </summary> public void Push(T val) { this.topNode = HeapNode.Meld(this.topNode, new HeapNode(val)); this.Count++; }
/// <summary> /// 捨てる /// </summary> public void Pop() { this.topNode = HeapNode.Meld(this.topNode.l, this.topNode.r); this.Count--; }
public void Merge(SkewHeap <T> otherHeap) { this.Count += otherHeap.Count; this.topNode = HeapNode.Meld(this.topNode, otherHeap.topNode); }