Exemplo n.º 1
0
node *rotate(node *tree,int num)
{
	if(num<tree->data)
	{
		if(tree->left !=NULL)
		{
//printf("%d\n",tree->data);
			if(tree->left->data==num)
			{
				tree=singleleft(tree);
			}
					else
			{tree->left=rotate(tree->left,num);
			}
		}
		return tree;
	}
	else if(num>tree->data)
	{
		if(tree->right!=NULL)
		{
//printf("i%d\n",tree->data);
			if(tree->right->data==num)
			{
				tree=singleright(tree);
			}
						else
			{tree->right=rotate(tree->right,num);
			}
		}
		return tree;
	}
}
Exemplo n.º 2
0
Arquivo: avl.c Projeto: CoryXie/nix-os
static void
balance(Avl **tp, Avl *p)
{
	switch((*tp)->bal){
	case -2:
		if((*tp)->n[0]->bal <= 0)
			singleright(tp, p);
		else if((*tp)->n[0]->bal == 1)
			doubleleftright(tp, p);
		else
			assert(0);
		break;

	case 2:
		if((*tp)->n[1]->bal >= 0)
			singleleft(tp, p);
		else if((*tp)->n[1]->bal == -1)
			doublerightleft(tp, p);
		else
			assert(0);
		break;
	}
}
Exemplo n.º 3
0
Arquivo: avl.c Projeto: CoryXie/nix-os
static void
doubleleftright(Avl **tp, Avl *p)
{
	singleleft(&(*tp)->n[0], *tp);
	singleright(tp, p);
}