AVL平衡二叉树

本文深入探讨了AVL平衡二叉树的概念,通过洛谷平台的典型平衡树模板题进行解析,阐述了AVL树如何保持平衡以及其在解决算法问题中的应用。
摘要由CSDN通过智能技术生成

一、洛谷普通平衡树模板题。。。。题目不好复制。

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<vector>
#define ll long long
#define llu unsigned ll
using namespace std;
const double alpha=0.75;
const int maxn=100100;
const int inf=0x3f3f3f3f;
struct node
{
   
    int val;
    int lc,rc;
    int h;
    int si;
}t[maxn];
int tot,root;


void pushup(int p)
{
   
    t[p].h=max(t[t[p].lc].h,t[t[p].rc].h)+1;
    t[p].si=t[t[p].lc].si+t[t[p].rc].si+1;
}

int getb(int p)
{
   
    return t[t[p].lc].h-t[t[p].rc].h;
}

int newnode(int x)
{
   
    int p=++tot;
    t[p].lc=t[p].rc=0;
    t[p].h=t[p].si=1;
    t[p].val=x;
    return p;
}

void R(int &p)
{
   
    int q=t
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值