Пример #1
0
bool BST<T>::contains(const T& v, BSTNode* &t, BSTNode*& parent)
{
	if (t == nullptr)
	{
		return false;
	}
	if (v == t->element)
	{
		t->search++;
		if (t->search == rotate_threshold_value)
		{
			t->search = 0;
			if (parent->left == t)
			{
				rotateLeftChild(parent);
			}	
			else if (parent->right == t)
			{
				rotateRightChild(parent);
			}
		}
		return true;
	}

	if (v < t->element)
	{
		return contains(v, t->left, t);

	}
	else
	{
		return contains(v, t->right, t);
	}

}
Пример #2
0
// Balancing AVL Tree
AVL_Node* AVLTreeIndex::balance(AVL_Node*& temp){
    int bal_factor = diff (temp);
    if (bal_factor > 1){
        if (diff (temp->left) > 0){ //if left node height difference is greater than 0 rotate left
            temp = rotateLeftChild (temp);
        }else{ //else rotate left
            temp = doubleLeftChild (temp);
        }
    }
    else if (bal_factor < -1){
        if (diff (temp->right) > 0){ //if right node height difference is greater than 0 rotate left
            temp = doubleRightChild (temp);
        }else{
            temp = rotateRightChild (temp);
        }
    }
    return temp;
    
}
Пример #3
0
// Right- Left Rotation
AVL_Node* AVLTreeIndex::doubleRightChild(AVL_Node *&parent){
    parent->right = rotateLeftChild (parent->right);
    return rotateRightChild (parent);
}