⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fig12_49.cpp

📁 经典书籍源代码啊。。。第三版。。。数据结构与算法分析——C++描述(第3版).
💻 CPP
字号:
    struct PairNode;
    typedef PairNode * Position;
    
    /**
     * Insert item x into the priority queue, maintaining heap order.
     * Return the Position  (a pointer to the node) containing the new item.
     */
    Position insert( const Comparable & x )
    {
        PairNode *newNode = new PairNode( x );
    
        if( root == NULL )
            root = newNode;
        else
            compareAndLink( root, newNode );
        return newNode;
    }
    
    /**
     * Change the value of the item stored in the pairing heap.
     * Throw IllegalArgumentException if newVal is larger than
     *    currently stored value.
     * p is a Position returned by insert.
     * newVal is the new value, which must be smaller
     *    than the currently stored value.
     */
    void decreaseKey( Position p, const Comparable & newVal )
    {
        if( p->element < newVal )
            throw IllegalArgumentException( );    // newVal cannot be bigger
        p->element = newVal;
        if( p != root )
        {
            if( p->nextSibling != NULL )
                p->nextSibling->prev = p->prev;
            if( p->prev->leftChild == p )
                p->prev->leftChild = p->nextSibling;
            else
                p->prev->nextSibling = p->nextSibling;
    
            p->nextSibling = NULL;
            compareAndLink( root, p );
        }
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -