src/ADT/Tree/BalanceBinaryNode.php
protected function balanceTree()
	{
		$bf	= $this->getBalance();
		if( $bf >= $this->balance ) 												// LR or LL rotation
		{
			$ll_height	= $this->left->left  ? $this->left->left->getHeight()  : 0;
			$lr_height	= $this->left->right ? $this->left->right->getHeight() : 0;
			if( $ll_height < $lr_height )
				$this->left->rotateRR(); 											// LR rotation
			$this->rotateLL();
		}
		else if( $bf <= $this->balance )											// RR or RL rotation
		{
			$rr_height	= $this->right->right ? $this->right->right->getHeight() : 0;
			$rl_height	= $this->right->left  ? $this->right->left->getHeight()  : 0;
			if( $rl_height > $rr_height )
				$this->right->rotateLL();											// RR rotation
			$this->rotateRR();
		}
	}
protected function balanceTree()
	{
		$bf	= $this->getBalance();
		if( $bf >= $this->balance ) 												// LR or LL rotation
		{
			$ll_height	= $this->left->left  ? $this->left->left->getHeight()  : 0;
			$lr_height	= $this->left->right ? $this->left->right->getHeight() : 0;
			if( $ll_height < $lr_height )
				$this->left->rotateRR(); 											// LR rotation
			$this->rotateLL();
		}
		else if( $bf <= $this->balance )											// RR or RL rotation
		{
			$rr_height	= $this->right->right ? $this->right->right->getHeight() : 0;
			$rl_height	= $this->right->left  ? $this->right->left->getHeight()  : 0;
			if( $rl_height > $rr_height )
				$this->right->rotateLL();											// RR rotation
			$this->rotateRR();
		}
	}
protected function balanceTree ( ) { $ bf = $ this -> getBalance ( ) ; if ( $ bf >= $ this -> balance ) // LR or LL rotation
 { $ ll_height = $ this -> left -> left ? $ this -> left -> left -> getHeight ( ) : 0 ; $ lr_height = $ this -> left -> right ? $ this -> left -> right -> getHeight ( ) : 0 ; if ( $ ll_height < $ lr_height ) $ this -> left -> rotateRR ( ) ; // LR rotation
 $ this -> rotateLL ( ) ; } else if ( $ bf <= $ this -> balance ) // RR or RL rotation
 { $ rr_height = $ this -> right -> right ? $ this -> right -> right -> getHeight ( ) : 0 ; $ rl_height = $ this -> right -> left ? $ this -> right -> left -> getHeight ( ) : 0 ; if ( $ rl_height > $ rr_height ) $ this -> right -> rotateLL ( ) ; // RR rotation
 $ this -> rotateRR ( ) ; } }
Balances unbalanced Tree with Rotations.
@access		public
@return		void
Balances unbalanced Tree with Rotations .