public Node PerfectBalanceThanos(Node Now) { int b_factor = avl.BalanceUiniverse(Now); if (b_factor > 1) { if (avl.BalanceUiniverse(Now.left) > 0) { Now = avl.RotationLL(Now); } else { Now = avl.RotationLR(Now); } } else if (b_factor < -1) { if (avl.BalanceUiniverse(Now.right) > 0) { Now = avl.RotationRL(Now); } else { Now = avl.RotationRR(Now); } } return(Now); }
public Node DeleteAVL(Node DeleteRoot, int deletevalue) { Node Child; if (DeleteRoot == null) { return(null); } else { if (deletevalue < DeleteRoot.value) { DeleteRoot.left = DeleteAVL(DeleteRoot.left, deletevalue); if (Del.BalanceUiniverse(DeleteRoot) == -2) { if (Del.BalanceUiniverse(DeleteRoot.right) <= 0) { DeleteRoot = Del.RotationRR(DeleteRoot); } else { DeleteRoot = Del.RotationRL(DeleteRoot); } } } else if (deletevalue > DeleteRoot.value) { DeleteRoot.right = DeleteAVL(DeleteRoot.right, deletevalue); if (Del.BalanceUiniverse(DeleteRoot) == 2) { if (Del.BalanceUiniverse(DeleteRoot.left) >= 0) { DeleteRoot = Del.RotationLL(DeleteRoot); } else { DeleteRoot = Del.RotationLR(DeleteRoot); } } } else { if (DeleteRoot.right != null) { Child = DeleteRoot.right; while (Child.left != null) { Child = Child.left; } DeleteRoot.value = Child.value; DeleteRoot.right = DeleteAVL(DeleteRoot.right, Child.value); if (Del.BalanceUiniverse(DeleteRoot) == 2) { if (Del.BalanceUiniverse(DeleteRoot.left) >= 0) { DeleteRoot = Del.RotationLL(DeleteRoot); } else { DeleteRoot = Del.RotationLR(DeleteRoot); } } } else { return(DeleteRoot.left); } } } return(DeleteRoot); }