左式堆的deletdMin例程

《数据结构与算法分析》书上的左式堆,deleteMin例程没有完整给出,自己试着实现一下:

ElementType deleteMin(priorityQueue H)
{
    ElementType Tmp;
    Tmp = findMin(H);
    deleteMin1(H);
    return Tmp;
}
priorityQueue deleteMin1(priorityQueue H)
{
    priorityQueue leftHeap, rightHeap;
    
    if(isEmpty(H))
    {
        Error("Priority queue is empty");
        return H;
    }

    leftHeap = H->Left;
    rightHeap = H->Right;
    free(H);
    return Merge(leftHeap, rightHeap);
}
ElementType findMin(priorityQueue H)
{
    if(isEmpty(H))
    {
        Error("Priority queue is empty");
        return -1;
    }
    else
        return H->Element;
}




你可能感兴趣的:(左式堆的deletdMin例程)