struct pairnodetypedef pairnode position/*insert item into the priority queuemaintaining heap order return the position ( pointer to the nodecontaining the new item *position insertconst comparable pairnode *newnode new pairnodex }ifroot =nullptr root newnodeelse compareandlinkrootnewnode )return newnode/*change the value of the item stored in the pairing heap throw invalid_argument if newval is larger than currently stored value is position returned by insert newval is the new valuewhich must be smaller than the currently stored value *void decreasekeyposition pconst comparable newval ifp->element newval throw invalid_argument"newval too large} ->element newvalifp !root ifp->nextsibling !nullptr ->nextsibling->prev ->previfp->prev->leftchild = ->prev->leftchild ->nextsiblingelse ->prev->nextsibling ->nextsiblingp->nextsibling nullptrcompareandlinkrootp )figure pairing heapsinsert and decreasekey