左偏树

#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()
{
    
}

 

posted @ 2017-10-31 16:33  探险家Mr.H  阅读(136)  评论(0编辑  收藏  举报