About from http://dsqiu.iteye.com/blog/1714961 1.Pairing heap
The Fibonacci Heap has two main drawbacks: the programming is difficult to implement and the actual efficiency is not as fast as the theory (due to its storage structure and four pointers). The pairing heap is made to compensate for the two drawbacks of the Fibonacci heaps-the time complexity of programming simple operations and the same as the Fibonacci heaps.
The pairing heap is actually a tree with a heap (maximum heap or minimum heap), whose properties are not determined by its structure, but by its operations (inserting, merging, reducing a keyword, and so on).
ADT for 1.1Pairing Heap
C code [CPP] view plain copy print? pairingheapnode {int key; struct pairingheapnode* child; struct pairingheapnode* sibling; struct pairingheapnode* prev; }pairheap;
operation of the 2.Pairing Heap
Note: The plot process is demonstrated with the largest heap, but the code is written in the smallest heap, forgive me. 2.1. Merging of two sub-stacks
C code[C] View plain copy print? Static pairheap* merge_subheaps (pairheap *p, pairheap *q) { if (q == null) return p; else if (P->key <= q->key) { q->prev = p; p->sibling = q->sibling; if (p->sibling != null) p->sibling->prev = p; q->sibling = p->child; if (q->sibling != null) q->sibling->prev = q; p->child = q; return p; } else { q->prev = p->prev; p->prev = q; p->sibling = q->child; if (P- >sibling != null) p->sibling->prev = p; q->child = p; return q; } }
2.2. Inserting a node
C code [C] view plain copy print? pairheap* Pairheap_insert (pairheap *p, int key) {pairheap *node; node = (pairheap*) malloc (sizeof (*node)); if (node = = NULL)