# Demo entry 6686607

c

Submitted by anonymous on Dec 24, 2017 at 08:50
Language: C. Code size: 5.5 kB.

```#include <stdio.h>
#include <stdlib.h>
typedef struct AVL_Node
{
int data; //数据
int height;//节点高度
}Node;
typedef Node* PNode;
int R(PNode *node);
int L(PNode *node );
void LL(PNode *node);
void RR(PNode *node);
int Height(PNode *node);
int Insert(PNode *node,int x);
int search(PNode node,int x);
void Delete(PNode *node,int x);

int R(PNode *node)
{
{
// printf("*\n");
RR(node);
}
else RR(node);
return 0;
}
int L(PNode *node )
{
{
// printf("*\n");
// printf("*\n");
LL(node);
}
else LL(node);
return 0;
}
void LL(PNode *node)
{
*node = temp;
}
void RR(PNode *node)
{

//    printf("!!!\n");

*node = temp;

}
int Height(PNode* node)
{
//    printf("***\n");
return (*node)== NULL ? -1 : (*node)->height;
}
int Insert(PNode *node,int x)
{
if((*node)==NULL)//节点为空插入这里
{
(*node) = (PNode)malloc(100*sizeof(Node));
(*node)->data = x;
(*node)->height = 0;
return 1;
}
else if(x == (*node)->data)//原来存在该节点返回0，递归结束
return 0;
else if(x<(*node)->data)//待插入节点的值小于当前的节点
{
return 0;  //返回0
{
//                printf("#1\n");
L(node); //左边高，再判断是LL型旋转还是LR型旋转
}
//        else printf("PP\n");
}
else if(x>(*node)->data)
{
return 0;
{
R(node);
//             printf("#2\n");
}
}
//    printf("*\n");
return 1;//返回1，保证递归继续向下走
}

int search(PNode node,int x)//查找
{
//PNode temp;
while(node!=NULL)
{
//  temp = node;
if(node->data == x)
{
return 1;
}
else if(x>node->data)
{
}
else if(x<node->data)
{
}
}
return 0;
}
void Inoreder(PNode tree)//中序遍历,打印树
{
if(tree == NULL)
return ;
else
{
printf("%d  ",tree->data);
}
}
void Delete(PNode *node,int x)//删除节点
{
if((*node)==NULL)//节点为空，不存在删除节点
return ;
else if(x>(*node)->data)
else if(x<(*node)->data)
else if(x == (*node)->data)
{
{
PNode temp = (*node);
free(temp);
}