Data Structures/Heaps/Pairing Heap.cpp
// All temporary heaps will have size = 0,
// insertion and deletion functions will maintain the correct size.
All temporary heaps will have size = 0,
insertion and deletion functions will maintain the correct size.
All temporary heaps will have size = 0 insertion and deletion functions will maintain the correct size .
void PairingHeap::Merge(PairingHeap* other) {
  Node* other_root = other -> root;
  if (root == NULL) {
    root = other_root;
    size = other -> size;
    return;
  }
  if (other_root != NULL) {
    if (root -> key < other_root -> key) {
      other_root -> left = root;
      other_root -> right = root -> first_child;
      if (root -> first_child != NULL) {
        root -> first_child -> left = other_root;
      }
      root -> first_child = other_root;
    } else {
      root -> left = other_root;
      root -> right = other_root -> first_child;
      if (other_root -> first_child != NULL) {
        other_root -> first_child -> left = root;
      }
      other_root -> first_child = root;
      root = other_root;
    }
    size += other -> size;
  }
}
void PairingHeap :: Merge ( PairingHeap * other ) { Node * other_root = other -> root ; if ( root == NULL ) { root = other_root ; size = other -> size ; return ; } if ( other_root != NULL ) { if ( root -> key < other_root -> key ) { other_root -> left = root ; other_root -> right = root -> first_child ; if ( root -> first_child != NULL ) { root -> first_child -> left = other_root ; } root -> first_child = other_root ; } else { root -> left = other_root ; root -> right = other_root -> first_child ; if ( other_root -> first_child != NULL ) { other_root -> first_child -> left = root ; } other_root -> first_child = root ; root = other_root ; } size += other -> size ; } }
All temporary heaps will have size = 0,
insertion and deletion functions will maintain the correct size.
All temporary heaps will have size = 0 insertion and deletion functions will maintain the correct size .