左偏树

#include<iostream>
using namespace std;
struct node
{  
    int w, lc, rc, h;  
}t[M];   
int merge(int A, int B)
{  
    if(!A) return B;  
    if(!B) return A;  
    if(t[A].w < t[B].w) swap(A, B);  
    t[A].rc = merge(t[A].rc, B);
    if(t[t[A].lc].h < t[t[A].rc].h) swap(t[A].lc, t[A].rc);  
    if(t[A].rc) t[A].h = t[A].rc+1;  
    else t[A].h = 0;  
    return A;  
}
void insert(int A, int x)
{  
    cnt++;  
    t[cnt].w = x;   
    merge(A, cnt);  
}
int pop(int A)
{  
    return merge(t[A].lc, t[A].rc);  
}
int main()
{
    
}
原文地址:https://www.cnblogs.com/Kong-Ruo/p/7762252.html